Class: SimpleApiKeyEngine::Providers::AbstractProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/simpleapikeyengine/providers/abstract_provider.rb

Constant Summary collapse

@@priorities =
{}

Class Method Summary collapse

Instance Method Summary collapse

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

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


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
# 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.auth_hash = auth_hash
  authentication.save!
  return authentication
end

#get_auth_hash!Object

Raises:

  • (NotImplementedError)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/simpleapikeyengine/providers/abstract_provider.rb', line 38

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