Class: OAuth2::Grant::Base

Inherits:
Object
  • Object
show all
Includes:
UrlHelper
Defined in:
lib/oauth2/grant/base.rb

Defined Under Namespace

Classes: InvalidAuthorizationTypeError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UrlHelper

#build_url, #generate_timestamp, #generate_urlsafe_key, http_basic_encode, #to_query

Constructor Details

#initialize(client) ⇒ Base



11
12
13
14
15
16
17
18
19
# File 'lib/oauth2/grant/base.rb', line 11

def initialize(client)
  @host           = client.host
  @connection     = client.connection
  @client_id      = client.client_id
  @client_secret  = client.client_secret
  @token_path     = client.token_path
  @authorize_path = client.authorize_path
  @device_path    = client.device_path
end

Instance Attribute Details

#authorize_pathObject

Returns the value of attribute authorize_path.



8
9
10
# File 'lib/oauth2/grant/base.rb', line 8

def authorize_path
  @authorize_path
end

#client_idObject

Returns the value of attribute client_id.



8
9
10
# File 'lib/oauth2/grant/base.rb', line 8

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



8
9
10
# File 'lib/oauth2/grant/base.rb', line 8

def client_secret
  @client_secret
end

#connectionObject

Returns the value of attribute connection.



8
9
10
# File 'lib/oauth2/grant/base.rb', line 8

def connection
  @connection
end

#device_pathObject

Returns the value of attribute device_path.



8
9
10
# File 'lib/oauth2/grant/base.rb', line 8

def device_path
  @device_path
end

#hostObject

Returns the value of attribute host.



8
9
10
# File 'lib/oauth2/grant/base.rb', line 8

def host
  @host
end

#token_pathObject

Returns the value of attribute token_path.



8
9
10
# File 'lib/oauth2/grant/base.rb', line 8

def token_path
  @token_path
end

Instance Method Details

#make_request(method, path, opts = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/oauth2/grant/base.rb', line 21

def make_request(method, path, opts={})
  if auth_type = opts.delete(:authenticate)
    case auth_type.to_sym
    when :body
      opts[:params] ||= {}
      opts[:params].merge!({
        :client_id     => @client_id,
        :client_secret => @client_secret
      })
    when :headers
      opts[:headers] ||= {}
      opts[:headers]['Authorization'] = http_basic_encode(@client_id, @client_secret)
    else
      #do nothing
    end
  end
  @connection.send_request(method, path, opts)
end