Class: OAuth2::Authenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/oauth2/authenticator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, secret, mode) ⇒ Authenticator

Returns a new instance of Authenticator.


7
8
9
10
11
# File 'lib/oauth2/authenticator.rb', line 7

def initialize(id, secret, mode)
  @id = id
  @secret = secret
  @mode = mode
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id


5
6
7
# File 'lib/oauth2/authenticator.rb', line 5

def id
  @id
end

#modeObject (readonly)

Returns the value of attribute mode


5
6
7
# File 'lib/oauth2/authenticator.rb', line 5

def mode
  @mode
end

#secretObject (readonly)

Returns the value of attribute secret


5
6
7
# File 'lib/oauth2/authenticator.rb', line 5

def secret
  @secret
end

Class Method Details

.encode_basic_auth(user, password) ⇒ Object


33
34
35
# File 'lib/oauth2/authenticator.rb', line 33

def self.encode_basic_auth(user, password)
  'Basic ' + Base64.strict_encode64(user + ':' + password)
end

Instance Method Details

#apply(params) ⇒ Hash

Apply the request credentials used to authenticate to the Authorization Server

Depending on configuration, this might be as request params or as an Authorization header.

User-provided params and header take precedence.

Parameters:

  • params (Hash)

    a Hash of params for the token endpoint

Returns:

  • (Hash)

    params amended with appropriate authentication details


22
23
24
25
26
27
28
29
30
31
# File 'lib/oauth2/authenticator.rb', line 22

def apply(params)
  case mode.to_sym
  when :basic_auth
    apply_basic_auth(params)
  when :request_body
    apply_params_auth(params)
  else
    raise NotImplementedError
  end
end