class G5AuthenticatableApi::Services::TokenInfo

Extract access token from request to retrieve token data from G5 Auth

Attributes

headers[R]
params[R]
warden[R]

Public Class Methods

new(params = {}, headers = {}, warden = nil) click to toggle source
# File lib/g5_authenticatable_api/services/token_info.rb, line 9
def initialize(params = {}, headers = {}, warden = nil)
  @params = params || {}
  @headers = headers || {}
  @warden = warden
end

Public Instance Methods

access_token() click to toggle source
# File lib/g5_authenticatable_api/services/token_info.rb, line 15
def access_token
  @access_token ||= begin
                      extract_token_from_header ||
                        extract_token_from_params ||
                        extract_token_from_warden
                    end
end
auth_client() click to toggle source
# File lib/g5_authenticatable_api/services/token_info.rb, line 27
def auth_client
  @auth_client ||= G5AuthenticationClient::Client.new(
    allow_password_credentials: 'false',
    access_token: access_token
  )
end
token_data() click to toggle source
# File lib/g5_authenticatable_api/services/token_info.rb, line 23
def token_data
  auth_client.token_info
end

Private Instance Methods

authorization_header() click to toggle source
# File lib/g5_authenticatable_api/services/token_info.rb, line 51
def authorization_header
  @headers['Authorization'] || @headers['AUTHORIZATION']
end
extract_token_from_header() click to toggle source
# File lib/g5_authenticatable_api/services/token_info.rb, line 36
def extract_token_from_header
  return unless authorization_header
  parts = authorization_header.match(/Bearer (?<access_token>\S+)/)
  parts['access_token']
end
extract_token_from_params() click to toggle source
# File lib/g5_authenticatable_api/services/token_info.rb, line 42
def extract_token_from_params
  return if params['access_token'].blank?
  params['access_token']
end
extract_token_from_warden() click to toggle source
# File lib/g5_authenticatable_api/services/token_info.rb, line 47
def extract_token_from_warden
  warden.try(:user).try(:g5_access_token)
end