Class: OAuth2::Rack::Authorization::RefreshToken::AccessTokenIssuer

Inherits:
Object
  • Object
show all
Defined in:
lib/oauth2/rack/authorization/refresh_token/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/refresh_token/access_token_issuer.rb', line 6

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

  @issuer = issuer || opts[: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
# File 'lib/oauth2/rack/authorization/refresh_token/access_token_issuer.rb', line 12

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

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

  if access_token['error']
    error_response(access_token)
  else
    access_token['token_type'] ||= 'bearer'
    successful_response(access_token)
  end
end