Class: Authinator::AuthCodeExchanger

Inherits:
Object
  • Object
show all
Defined in:
lib/authinator/auth_code_exchanger.rb

Constant Summary collapse

VALID_PROVIDERS =
[:stub, :google]
STUB_SAMPLE_TOKEN =
{
  token: 'ya29.token',
  refresh_token: '1/refresh',
  expires_in: 3600,
}
PROVIDER_HASHES =
{
  google: {
    client_id: 'cl_id',
    client_secret: 'cl_sec',
    site: 'https://accounts.google.com',
    token_url: '/o/oauth2/token',
  },
  stub: {
    client_id: 'cl_id',
    client_secret: 'cl_sec',
    site: 'https://example.org',
    token_url: '/extoken',
  },
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider, client_options = {}) ⇒ AuthCodeExchanger

Returns a new instance of AuthCodeExchanger.



35
36
37
38
39
40
41
42
43
44
# File 'lib/authinator/auth_code_exchanger.rb', line 35

def initialize(provider, client_options = {})
  unless VALID_PROVIDERS.include? provider
    fail ArgumentError,
         "Provider #{provider} not in supported parameter list:\n" <<
           VALID_PROVIDERS.inspect
  end

  @provider = provider
  build_provider_hash(client_options)
end

Instance Attribute Details

#providerObject (readonly)

Returns the value of attribute provider.



14
15
16
# File 'lib/authinator/auth_code_exchanger.rb', line 14

def provider
  @provider
end

Class Method Details

.valid_providersObject



16
17
18
# File 'lib/authinator/auth_code_exchanger.rb', line 16

def self.valid_providers
  VALID_PROVIDERS
end

Instance Method Details

#exchange(auth_code) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/authinator/auth_code_exchanger.rb', line 50

def exchange(auth_code)
  # auth_code = params[:code]
  return if auth_code.nil? || auth_code.empty?

  case @provider.to_sym
  when :google
    exchange_with_google(auth_code)
  when :stub
    exchange_with_stub(auth_code)
  end
end

#site_token_urlObject



46
47
48
# File 'lib/authinator/auth_code_exchanger.rb', line 46

def site_token_url
  @provider_hash[:site] + @provider_hash[:token_url]
end