Class: Platforms::Core::OmniAuthSetup

Inherits:
Object
  • Object
show all
Defined in:
lib/platforms/core/omni_auth_setup.rb

Overview

Handles the dynamic insertion of client ID and Client Secret into the OmniAuth regime.

See Also:

Author:

  • Benjamin Elias

Since:

  • 0.1.0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ OmniAuthSetup

Assign variables and create a request object for use later. env - Rack environment

Since:

  • 0.1.0



22
23
24
25
# File 'lib/platforms/core/omni_auth_setup.rb', line 22

def initialize(env)
  @env = env
  @request = ActionDispatch::Request.new(env)
end

Class Method Details

.call(env) ⇒ Object

OmniAuth expects the class passed to setup to respond to the #call method.

Parameters:

  • env (Hash)

    Rack environment

Since:

  • 0.1.0



16
17
18
# File 'lib/platforms/core/omni_auth_setup.rb', line 16

def self.call(env)
  new(env).setup
end

Instance Method Details

#default_certificateObject

As a placeholder, return a blank certificate

Since:

  • 0.1.0



47
48
49
# File 'lib/platforms/core/omni_auth_setup.rb', line 47

def default_certificate
  Certificate.new
end

#find_credentialsObject

Use the subdomain in the request to find the account with credentials

Since:

  • 0.1.0



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/platforms/core/omni_auth_setup.rb', line 33

def find_credentials
  strategy = @env['omniauth.strategy'].options.name
  subdomain = ActionDispatch::Http::URL.extract_subdomains(@env['SERVER_NAME'], 0).first

  certificate = Certificate.find_by(
    strategy: strategy,
    name: subdomain
  )
  # If subdomain-specific certificate is not found, use default
  certificate ||= default_certificate
  return certificate.credentials
end

#setupObject

The main purpose of this method is to set the consumer key and secret.

Since:

  • 0.1.0



28
29
30
# File 'lib/platforms/core/omni_auth_setup.rb', line 28

def setup
  @env['omniauth.strategy'].options.merge!(find_credentials)
end