Class: SimpleApiKeyEngine::Providers::AbstractProvider
- Inherits:
-
Object
- Object
- SimpleApiKeyEngine::Providers::AbstractProvider
- Defined in:
- lib/simpleapikeyengine/providers/abstract_provider.rb
Constant Summary collapse
- @@priorities =
{}
Class Method Summary collapse
Instance Method Summary collapse
- #auth(&block) ⇒ Object
- #get_auth_hash! ⇒ Object
-
#initialize(params) ⇒ AbstractProvider
constructor
A new instance of AbstractProvider.
Constructor Details
#initialize(params) ⇒ AbstractProvider
Returns a new instance of AbstractProvider.
20 21 22 |
# File 'lib/simpleapikeyengine/providers/abstract_provider.rb', line 20 def initialize(params) @params = params end |
Class Method Details
.acceptable?(auth_hash) ⇒ Boolean
15 16 17 |
# File 'lib/simpleapikeyengine/providers/abstract_provider.rb', line 15 def acceptable?(auth_hash) raise NotImplementedError end |
.priority(val = nil) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/simpleapikeyengine/providers/abstract_provider.rb', line 7 def priority(val=nil) if val.present? @@priorities[self] = val else @@priorities[self] end end |
Instance Method Details
#auth(&block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/simpleapikeyengine/providers/abstract_provider.rb', line 24 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! return authentication end |
#get_auth_hash! ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/simpleapikeyengine/providers/abstract_provider.rb', line 40 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 |