class SimpleApiKeyEngine::Providers::AbstractProvider

Public Class Methods

acceptable?(request) click to toggle source
# File lib/simpleapikeyengine/providers/abstract_provider.rb, line 15
def acceptable?(request)
  raise NotImplementedError
end
new(request) click to toggle source
# File lib/simpleapikeyengine/providers/abstract_provider.rb, line 20
def initialize(request)
  @request = request
  @params = request.params
end
priority(val=nil) click to toggle source
# File lib/simpleapikeyengine/providers/abstract_provider.rb, line 7
def priority(val=nil)
  if val.present?
    @@priorities[self] = val
  else
    @@priorities[self]
  end
end

Public Instance Methods

after_authentication(authentication) click to toggle source
# File lib/simpleapikeyengine/providers/abstract_provider.rb, line 62
def after_authentication(authentication)
  true
end
auth(&block) click to toggle source
# File lib/simpleapikeyengine/providers/abstract_provider.rb, line 25
def auth(&block)
  auth_hash = get_auth_hash!
  authentication = ::SimpleApiKeyEngine::Authentication.find_by_provider_and_uid(auth_hash[:provider], auth_hash[:uid])
  unless authentication
    authentication = ::SimpleApiKeyEngine::Authentication.new(provider: auth_hash[:provider],
                                                              uid: auth_hash[:uid])
    authentication.user = block.call(auth_hash)
  end
  authentication.token = auth_hash[:credentials][:token]
  authentication.expires_at = auth_hash[:credentials][:expires] ?
    Time.at(auth_hash[:credentials][:expires_at]) : nil
  authentication.auth_hash = auth_hash
  authentication.save!
  after_authentication(authentication)
  return authentication
end
get_auth_hash!() click to toggle source
# File lib/simpleapikeyengine/providers/abstract_provider.rb, line 42
def get_auth_hash!
  # {
  #     provider: 'provider_key',
  #     uid: user_info['id'],
  #     credentials: {
  #         token: 'OAuth2Token',
  #         expires_at: expires_at,
  #         expires: expires
  #     },
  #     info: {
  #         email: user_info['email'],
  #         name: user_info['name']
  #     },
  #     extra: {
  #         raw_info: user_info.to_h
  #     }
  # }
  raise NotImplementedError
end