Class: OmniAuth::Configuration

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

Constant Summary collapse

@@defaults =
{
  :camelizations => {},
  :path_prefix => '/auth',
  :on_failure => Proc.new do |env|
    message_key = env['omniauth.error.type']
    new_path = "#{env['SCRIPT_NAME']}#{OmniAuth.config.path_prefix}/failure?message=#{message_key}"
    [302, {'Location' => new_path, 'Content-Type'=> 'text/html'}, []]
  end,
  :form_css => Form::DEFAULT_CSS,
  :test_mode => false,
  :allowed_request_methods => [:get, :post],
  :mock_auth => {
    :default => AuthHash.new(
      'provider' => 'default',
      'uid' => '1234',
      'info' => {
        'name' => 'Bob Example'
      }
    )
  }
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



48
49
50
# File 'lib/omniauth.rb', line 48

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

Instance Attribute Details

#allowed_request_methodsObject

Returns the value of attribute allowed_request_methods.



92
93
94
# File 'lib/omniauth.rb', line 92

def allowed_request_methods
  @allowed_request_methods
end

#camelizationsObject

Returns the value of attribute camelizations.



92
93
94
# File 'lib/omniauth.rb', line 92

def camelizations
  @camelizations
end

#form_cssObject

Returns the value of attribute form_css.



92
93
94
# File 'lib/omniauth.rb', line 92

def form_css
  @form_css
end

#full_hostObject

Returns the value of attribute full_host.



92
93
94
# File 'lib/omniauth.rb', line 92

def full_host
  @full_host
end

#mock_authObject

Returns the value of attribute mock_auth.



92
93
94
# File 'lib/omniauth.rb', line 92

def mock_auth
  @mock_auth
end

#on_failure(&block) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/omniauth.rb', line 52

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

#path_prefixObject

Returns the value of attribute path_prefix.



92
93
94
# File 'lib/omniauth.rb', line 92

def path_prefix
  @path_prefix
end

#test_modeObject

Returns the value of attribute test_mode.



92
93
94
# File 'lib/omniauth.rb', line 92

def test_mode
  @test_mode
end

Class Method Details

.defaultsObject



44
45
46
# File 'lib/omniauth.rb', line 44

def self.defaults
  @@defaults
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'



87
88
89
# File 'lib/omniauth.rb', line 87

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

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



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/omniauth.rb', line 60

def add_mock(provider, mock={})
  # Stringify keys recursively one level.
  mock.keys.each do |key|
    mock[key.to_s] = mock.delete(key)
  end
  mock.each_pair do |key, val|
    if val.is_a? Hash
      val.keys.each do |subkey|
        val[subkey.to_s] = val.delete(subkey)
      end
    end
  end

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

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