class Platforms::Core::OmniAuthSetup

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

@author Benjamin Elias @since 0.1.0 @see www.createdbypete.com/dynamic-omniauth-provider-setup/ Dynamic providers. @see github.com/omniauth/omniauth/wiki/Setup-Phase OmniAuth Setup Phase

Public Class Methods

call(env) click to toggle source

OmniAuth expects the class passed to setup to respond to the call method. @param env [Hash] Rack environment

# File lib/platforms/core/omni_auth_setup.rb, line 16
def self.call(env)
  new(env).setup
end
new(env) click to toggle source

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

# File lib/platforms/core/omni_auth_setup.rb, line 22
def initialize(env)
  @env = env
  @request = ActionDispatch::Request.new(env)
end

Public Instance Methods

default_certificate() click to toggle source

As a placeholder, return a blank certificate

# File lib/platforms/core/omni_auth_setup.rb, line 47
def default_certificate
  Certificate.new
end
find_credentials() click to toggle source

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

# 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
setup() click to toggle source

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

# File lib/platforms/core/omni_auth_setup.rb, line 28
def setup
  @env['omniauth.strategy'].options.merge!(find_credentials)
end