Class: OAuth2::Provider::Rack::AuthorizationCodeRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/oauth2/provider/rack/authorization_code_request.rb

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ AuthorizationCodeRequest


3
4
5
6
# File 'lib/oauth2/provider/rack/authorization_code_request.rb', line 3

def initialize(params)
  @params = params
  validate!
end

Instance Method Details

#clientObject


38
39
40
# File 'lib/oauth2/provider/rack/authorization_code_request.rb', line 38

def client
  @client ||= OAuth2::Provider.client_class.from_param(client_id)
end

#client_idObject


34
35
36
# File 'lib/oauth2/provider/rack/authorization_code_request.rb', line 34

def client_id
  @params['client_id']
end

#deny!Object


26
27
28
# File 'lib/oauth2/provider/rack/authorization_code_request.rb', line 26

def deny!
  throw_response Responses.redirect_with_error('access_denied', redirect_uri)
end

#grant!(resource_owner = nil, authorization_expires_at = nil) ⇒ Object


8
9
10
11
12
13
14
15
16
17
# File 'lib/oauth2/provider/rack/authorization_code_request.rb', line 8

def grant!(resource_owner = nil, authorization_expires_at = nil)
  grant = client.authorizations.create!(
    :resource_owner => resource_owner,
    :client => client,
    :scope => scope,
    :expires_at => authorization_expires_at
  )
  code = grant.authorization_codes.create! :redirect_uri => redirect_uri
  throw_response Responses.redirect_with_code(code.code, redirect_uri)
end

#grant_existing!(resource_owner = nil) ⇒ Object


19
20
21
22
23
24
# File 'lib/oauth2/provider/rack/authorization_code_request.rb', line 19

def grant_existing!(resource_owner = nil)
  if existing = OAuth2::Provider.authorization_class.allowing(client, resource_owner, scope).first
    code = existing.authorization_codes.create! :redirect_uri => redirect_uri
    throw_response Responses.redirect_with_code(code.code, redirect_uri)
  end
end

#invalid_scope!Object


30
31
32
# File 'lib/oauth2/provider/rack/authorization_code_request.rb', line 30

def invalid_scope!
  throw_response Responses.redirect_with_error('invalid_scope', redirect_uri)
end

#redirect_uriObject


42
43
44
# File 'lib/oauth2/provider/rack/authorization_code_request.rb', line 42

def redirect_uri
  @params['redirect_uri']
end

#redirect_uri_valid?Boolean


46
47
48
# File 'lib/oauth2/provider/rack/authorization_code_request.rb', line 46

def redirect_uri_valid?
  client && client.allow_redirection?(redirect_uri)
end

#scopeObject


50
51
52
# File 'lib/oauth2/provider/rack/authorization_code_request.rb', line 50

def scope
  @params['scope']
end