Class: Songkick::OAuth2::Provider::AccessToken

Inherits:
Object
  • Object
show all
Defined in:
lib/songkick/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.


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

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


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

def authorization
  @authorization
end

Instance Method Details

#clientObject


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

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

#ownerObject


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

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

#response_headersObject


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

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


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

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)

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

def valid?
  @error.nil?
end