Class: OAuth2::Rack::Authorization::Password::AccessTokenIssuer

Inherits:
Object
  • Object
show all
Defined in:
lib/oauth2/rack/authorization/password/access_token_issuer.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, opts = {}, &issuer) ⇒ AccessTokenIssuer

Returns a new instance of AccessTokenIssuer



6
7
8
9
10
# File 'lib/oauth2/rack/authorization/password/access_token_issuer.rb', line 6

def initialize(app, opts = {}, &issuer)
  @app = app

  @issuer = issuer || opts.delete(:issuer)
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/oauth2/rack/authorization/password/access_token_issuer.rb', line 12

def call(env)
  resource_owner = env['oauth2.resource_owner']
  unless resource_owner
    return error_response(:error => 'invalid_grant')
  end

  request = Rack::Request.new(env)
  unless request['grant_type'] == 'password'
    return error_response(:error => 'invalid_request')
  end

  # oauth2.client is set in client authentication
  access_token = find_acccess_token(:grant_type => 'password',
                                    :resource_owner => resource_owner,
                                    :client => env['oath2.client'],
                                    :scope => request['scope'])

  if access_token['error']
    error_response(access_token)
  else
    successful_response(access_token)
  end
end