Class: OmniAuth::Configuration

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/omniauth.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



56
57
58
# File 'lib/omniauth.rb', line 56

def initialize
  self.class.defaults.each_pair { |k, v| send("#{k}=", v) }
end

Instance Attribute Details

#allowed_request_methodsObject

Returns the value of attribute allowed_request_methods.



130
131
132
# File 'lib/omniauth.rb', line 130

def allowed_request_methods
  @allowed_request_methods
end

#before_callback_phase(&block) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/omniauth.rb', line 68

def before_callback_phase(&block)
  if block_given?
    @before_callback_phase = block
  else
    @before_callback_phase
  end
end

#before_options_phase(&block) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/omniauth.rb', line 76

def before_options_phase(&block)
  if block_given?
    @before_options_phase = block
  else
    @before_options_phase
  end
end

#before_request_phase(&block) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/omniauth.rb', line 92

def before_request_phase(&block)
  if block_given?
    @before_request_phase = block
  else
    @before_request_phase
  end
end

#camelizationsObject

Returns the value of attribute camelizations.



130
131
132
# File 'lib/omniauth.rb', line 130

def camelizations
  @camelizations
end

#failure_raise_out_environmentsObject

Returns the value of attribute failure_raise_out_environments.



130
131
132
# File 'lib/omniauth.rb', line 130

def failure_raise_out_environments
  @failure_raise_out_environments
end

#form_cssObject

Returns the value of attribute form_css.



130
131
132
# File 'lib/omniauth.rb', line 130

def form_css
  @form_css
end

#full_hostObject

Returns the value of attribute full_host.



130
131
132
# File 'lib/omniauth.rb', line 130

def full_host
  @full_host
end

#loggerObject

Returns the value of attribute logger.



130
131
132
# File 'lib/omniauth.rb', line 130

def logger
  @logger
end

#mock_authObject

Returns the value of attribute mock_auth.



130
131
132
# File 'lib/omniauth.rb', line 130

def mock_auth
  @mock_auth
end

#on_failure(&block) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/omniauth.rb', line 60

def on_failure(&block)
  if block_given?
    @on_failure = block
  else
    @on_failure
  end
end

#path_prefixObject

Returns the value of attribute path_prefix.



130
131
132
# File 'lib/omniauth.rb', line 130

def path_prefix
  @path_prefix
end

#request_validation_phase(&block) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/omniauth.rb', line 84

def request_validation_phase(&block)
  if block_given?
    @request_validation_phase = block
  else
    @request_validation_phase
  end
end

#silence_get_warningObject

Returns the value of attribute silence_get_warning.



130
131
132
# File 'lib/omniauth.rb', line 130

def silence_get_warning
  @silence_get_warning
end

#test_modeObject

Returns the value of attribute test_mode.



130
131
132
# File 'lib/omniauth.rb', line 130

def test_mode
  @test_mode
end

Class Method Details

.default_loggerObject



31
32
33
34
35
# File 'lib/omniauth.rb', line 31

def self.default_logger
  logger = Logger.new(STDOUT)
  logger.progname = 'omniauth'
  logger
end

.defaultsObject

rubocop:disable MethodLength



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/omniauth.rb', line 37

def self.defaults # rubocop:disable MethodLength
  @defaults ||= {
    :camelizations => {},
    :path_prefix => '/auth',
    :on_failure => OmniAuth::FailureEndpoint,
    :failure_raise_out_environments => ['development'],
    :request_validation_phase => OmniAuth::AuthenticityTokenProtection,
    :before_request_phase   => nil,
    :before_callback_phase  => nil,
    :before_options_phase   => nil,
    :form_css => Form::DEFAULT_CSS,
    :test_mode => false,
    :logger => default_logger,
    :allowed_request_methods => %i[post],
    :mock_auth => {:default => AuthHash.new('provider' => 'default', 'uid' => '1234', 'info' => {'name' => 'Example User'})},
    :silence_get_warning => false
  }
end

Instance Method Details

#add_camelization(name, camelized) ⇒ Object

This is a convenience method to be used by strategy authors so that they can add special cases to the camelization utility method that allows OmniAuth::Builder to work.

Parameters:

  • name (String)

    The underscored name, e.g. oauth

  • camelized (String)

    The properly camelized name, e.g. 'OAuth'



125
126
127
# File 'lib/omniauth.rb', line 125

def add_camelization(name, camelized)
  camelizations[name.to_s] = camelized.to_s
end

#add_mock(provider, original = {}) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/omniauth.rb', line 100

def add_mock(provider, original = {})
  # Create key-stringified new hash from given auth hash
  mock = {}
  original.each_pair do |key, val|
    mock[key.to_s] = if val.is_a? Hash
                       Hash[val.each_pair { |k, v| [k.to_s, v] }]
                     else
                       val
                     end
  end

  # Merge with the default mock and ensure provider is correct.
  mock = mock_auth[:default].dup.merge(mock)
  mock['provider'] = provider.to_s

  # Add it to the mocks.
  mock_auth[provider.to_sym] = mock
end