Class: OAuth2::Rack::Authorization::ClientCredentials::AccessTokenIssuer

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

Instance Method Summary (collapse)

Constructor Details

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

Returns a new instance of AccessTokenIssuer



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

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

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

Instance Method Details

- (Object) call(env)



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

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

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

  access_token = find_acccess_token(:grant_type => 'client_credentials',
                                    :client => client,
                                    :scope => request['scope'])

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