Class: HolisticAuth::Providers::Stub

Inherits:
GenericProvider show all
Defined in:
lib/holistic_auth/providers/stub.rb

Constant Summary collapse

SETTINGS =
{
  client_id: 'stub_cl_id',
  client_secret: 'stub_cl_sec',
  site: 'https://example.org',
  token_url: '/extoken',
  api_key: 'api_key',
  user_info_url: 'http://example.org/info',
}.freeze
STUB_SAMPLE_TOKEN =
{
  token: 'ya29.token',
  refresh_token: '1/refresh',
  expires_in: 3600,
}.freeze

Instance Attribute Summary

Attributes inherited from GenericProvider

#api_key, #client_id, #client_secret, #oauth2_client, #site, #tenant_id, #token_url, #user_info_url

Instance Method Summary collapse

Methods inherited from GenericProvider

#add_secrets, #empty?, #full_site_url, #present?, #secrets, #site_token_url, #to_hash

Constructor Details

#initialize(options = {}) ⇒ Stub

Returns a new instance of Stub.



19
20
21
22
23
24
25
# File 'lib/holistic_auth/providers/stub.rb', line 19

def initialize(options = {})
  super(options)

  @client_id ||= settings[:client_id]
  @client_secret ||= settings[:client_secret]
  @api_key ||= settings[:api_key]
end

Instance Method Details

#exchange(_, __) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/holistic_auth/providers/stub.rb', line 35

def exchange(_, __)
  @client = OAuth2::Client.new(
    client_id,
    client_secret,
  )

  OAuth2::AccessToken.new(
    @client,
    STUB_SAMPLE_TOKEN[:token],
    refresh_token: STUB_SAMPLE_TOKEN[:refresh_token],
    expires_in: STUB_SAMPLE_TOKEN[:expires_in],
  )
end

#nameObject



31
32
33
# File 'lib/holistic_auth/providers/stub.rb', line 31

def name
  :stub
end

#retrieve_user_info(_access_token) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/holistic_auth/providers/stub.rb', line 49

def (_access_token)
  {
    email_verified: true,
    email: '[email protected]',
    given_name: 'first',
    family_name: 'last',
    profile: 'xyz',
  }.with_indifferent_access
end

#settingsObject



27
28
29
# File 'lib/holistic_auth/providers/stub.rb', line 27

def settings
  SETTINGS
end