Class: OAuth2::Provider::AccessToken

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_owner = nil, scopes = [], access_token = nil, error = nil) ⇒ AccessToken

Returns a new instance of AccessToken.



7
8
9
10
11
12
13
14
15
# File 'lib/oauth2/provider/access_token.rb', line 7

def initialize(resource_owner = nil, scopes = [], access_token = nil, error = nil)
  @resource_owner = resource_owner
  @scopes         = scopes
  @access_token   = access_token
  @error          = error && INVALID_REQUEST
  
  authorize!(access_token, error)
  validate!
end

Instance Attribute Details

#authorizationObject (readonly)

Returns the value of attribute authorization.



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

def authorization
  @authorization
end

Instance Method Details

#clientObject



17
18
19
# File 'lib/oauth2/provider/access_token.rb', line 17

def client
  valid? ? @authorization.client : nil
end

#ownerObject



21
22
23
# File 'lib/oauth2/provider/access_token.rb', line 21

def owner
  valid? ? @authorization.owner : nil
end

#response_headersObject



25
26
27
28
29
30
# File 'lib/oauth2/provider/access_token.rb', line 25

def response_headers
  return {} if valid?
  error_message =  "OAuth realm='#{ Provider.realm }'"
  error_message << ", error='#{ @error }'" unless @error == ''
  {'WWW-Authenticate' => error_message}
end

#response_statusObject



32
33
34
35
36
37
38
39
# File 'lib/oauth2/provider/access_token.rb', line 32

def response_status
  case @error
    when INVALID_REQUEST, INVALID_TOKEN, EXPIRED_TOKEN then 401
    when INSUFFICIENT_SCOPE                            then 403
    when ''                                            then 401
                                                       else 200
  end
end

#valid?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/oauth2/provider/access_token.rb', line 41

def valid?
  @error.nil?
end