Class: Rack::OAuth2Utils::OAuthRequest

Inherits:
Request
  • Object
show all
Defined in:
lib/rack-oauth2_utils/oauth_request.rb

Constant Summary collapse

AUTHORIZATION_KEYS =
%w{HTTP_AUTHORIZATION X-HTTP_AUTHORIZATION X_HTTP_AUTHORIZATION}

Instance Method Summary collapse

Instance Method Details

#access_tokenObject

If OAuth, returns access token.



35
36
37
# File 'lib/rack-oauth2_utils/oauth_request.rb', line 35

def access_token
  @access_token ||= oauth?
end

#authorization_headerObject

Returns authorization header.



13
14
15
16
17
18
19
20
21
22
# File 'lib/rack-oauth2_utils/oauth_request.rb', line 13

def authorization_header
  @authorization_header ||= (
    h = AUTHORIZATION_KEYS.inject(nil) { |auth, key| auth || @env[key] }
    if h && h[/^oauth/i]
      h.gsub(/\n/, "").split[1]
    else
      nil
    end
  )
end

#authorization_paramObject



24
25
26
# File 'lib/rack-oauth2_utils/oauth_request.rb', line 24

def authorization_param
  @authorization_param ||= self.GET['access_token']
end

#oauth?Boolean

True if authentication scheme is OAuth.

Returns:

  • (Boolean)


29
30
31
# File 'lib/rack-oauth2_utils/oauth_request.rb', line 29

def oauth?
  authorization_header || authorization_param
end