Class: Songkick::OAuth2::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/songkick/oauth2/router.rb

Class Method Summary collapse

Class Method Details

.access_token(resource_owner, scopes, env) ⇒ Object


31
32
33
34
35
36
37
# File 'lib/songkick/oauth2/router.rb', line 31

def access_token(resource_owner, scopes, env)
  access_token = access_token_from_request(env)
  Provider::AccessToken.new(resource_owner,
                            scopes,
                            access_token,
                            detect_transport_error(env))
end

.access_token_from_request(env) ⇒ Object


39
40
41
42
43
44
45
46
47
# File 'lib/songkick/oauth2/router.rb', line 39

def access_token_from_request(env)
  request = request_from(env)
  params  = request.params
  header  = request.env['HTTP_AUTHORIZATION']

  header && header =~ /^OAuth\s+/ ?
      header.gsub(/^OAuth\s+/, '') :
      params[OAUTH_TOKEN]
end

.parse(resource_owner, env) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/songkick/oauth2/router.rb', line 11

def parse(resource_owner, env)
  error   = detect_transport_error(env)
  request = request_from(env)
  params  = request.params
  auth    = auth_params(env)

  if auth[CLIENT_ID] and auth[CLIENT_ID] != params[CLIENT_ID]
    error ||= Provider::Error.new("#{CLIENT_ID} from Basic Auth and request body do not match")
  end

  params = params.merge(auth)

  if params[GRANT_TYPE]
    error ||= Provider::Error.new('must be a POST request') unless request.post?
    Provider::Exchange.new(resource_owner, params, error)
  else
    Provider::Authorization.new(resource_owner, params, error)
  end
end