Module: Auth0::Mixins::Initializer

Included in:
Auth0::Mixins
Defined in:
lib/auth0/mixins/initializer.rb

Overview

Help class where Auth0::Client initialization described

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

including initializer in top of klass



33
34
35
# File 'lib/auth0/mixins/initializer.rb', line 33

def self.included(klass)
  klass.send :prepend, Initializer
end

Instance Method Details

#authorization_header(token) ⇒ Object



37
38
39
# File 'lib/auth0/mixins/initializer.rb', line 37

def authorization_header(token)
  add_headers("Authorization" => "Bearer #{token}")
end

#authorization_header_basic(options) ⇒ Object



41
42
43
44
45
46
# File 'lib/auth0/mixins/initializer.rb', line 41

def authorization_header_basic(options)
  connection_id = options.fetch(:connection_id, Auth0::Api::AuthenticationEndpoints::UP_AUTH)
  user = options.fetch(:user, nil)
  password = options.fetch(:password, nil)
  add_headers("Authorization" => "Basic #{Base64.strict_encode64("#{connection_id}\\#{user}:#{password}")}")
end

#initialize(config) ⇒ Object

Default initialization mechanism, moved here to keep Auth0::Client clear accepts hash as parameter you can get all required fields from here: auth0.com/docs/auth-api



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/auth0/mixins/initializer.rb', line 12

def initialize(config)
  options = config.transform_keys(&:to_sym)
  @base_uri = base_url(options)
  @headers = client_headers
  @timeout = options[:timeout] || 10
  @retry_count = options[:retry_count]
  @client_assertion_signing_key = options[:client_assertion_signing_key]
  @client_assertion_signing_alg = options[:client_assertion_signing_alg] || "RS256"
  @token_provider = options[:token_provider]
  @management_timeout = options[:management_timeout]
  @management_max_retries = options[:management_max_retries]
  @management_additional_headers = options[:management_additional_headers]
  extend Auth0::Api::AuthenticationEndpoints

  @client_id = options[:client_id]
  @client_secret = options[:client_secret]
  @organization = options[:organization]
  initialize_api(options)
end