class GrapeTokenAuth::AuthorizerData

Constants

RACK_ENV_KEY

Attributes

authed_with_token[RW]
client_id[R]
expiry[R]
skip_auth_headers[RW]
token[R]
uid[R]
warden[R]

Public Class Methods

data_from_env(env) click to toggle source
# File lib/grape_token_auth/authorizer_data.rb, line 27
def self.data_from_env(env)
  [Configuration::UID_KEY,
   Configuration::CLIENT_KEY,
   Configuration::ACCESS_TOKEN_KEY,
   Configuration::EXPIRY_KEY].map do |key|
    env[key] || env['HTTP_' + key.gsub('-', '_').upcase]
  end
end
from_env(env) click to toggle source
# File lib/grape_token_auth/authorizer_data.rb, line 19
def self.from_env(env)
  data = new(
    *data_from_env(env),
    env['warden']
  )
  inject_into_env(data, env)
end
inject_into_env(data, env) click to toggle source
# File lib/grape_token_auth/authorizer_data.rb, line 36
def self.inject_into_env(data, env)
  env[RACK_ENV_KEY] = data
end
load_from_env_or_create(env) click to toggle source
# File lib/grape_token_auth/authorizer_data.rb, line 40
def self.load_from_env_or_create(env)
  env[RACK_ENV_KEY] || from_env(env)
end
new(uid = nil, client_id = nil, token = nil, expiry = nil, warden = nil) click to toggle source
# File lib/grape_token_auth/authorizer_data.rb, line 8
def initialize(uid = nil, client_id = nil, token = nil,
               expiry = nil, warden = nil)
  @uid = uid
  @client_id = client_id || 'default'
  @token = token
  @expiry = expiry
  @warden = warden
  @authed_with_token = false
  @skip_auth_headers = false
end

Public Instance Methods

exisiting_warden_user(scope) click to toggle source
# File lib/grape_token_auth/authorizer_data.rb, line 44
def exisiting_warden_user(scope)
  warden_user =  warden.user(scope)
  return unless warden_user && warden_user.tokens[client_id].nil?
  resource = warden_user
  resource.create_new_auth_token
  resource
end
fetch_stored_resource(scope) click to toggle source
# File lib/grape_token_auth/authorizer_data.rb, line 56
def fetch_stored_resource(scope)
  warden.user(scope)
end
first_authenticated_resource() click to toggle source
# File lib/grape_token_auth/authorizer_data.rb, line 64
def first_authenticated_resource
  GrapeTokenAuth.configuration.mappings.each do |scope, _class|
    resource = fetch_stored_resource(scope)
    return resource if resource
  end
  nil
end
store_resource(resource, scope) click to toggle source
# File lib/grape_token_auth/authorizer_data.rb, line 60
def store_resource(resource, scope)
  warden.set_user(resource, scope: scope, store: false)
end
token_prerequisites_present?() click to toggle source
# File lib/grape_token_auth/authorizer_data.rb, line 52
def token_prerequisites_present?
  !token.nil? && !uid.nil?
end