omniauth 2.1.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/omniauth.rb CHANGED
@@ -1,7 +1,3 @@
1
- # TODO: Fixed in https://github.com/rack/rack/pull/1610 for Rack 3
2
- if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
3
- require 'delegate'
4
- end
5
1
  require 'rack'
6
2
  require 'singleton'
7
3
  require 'logger'
@@ -29,19 +25,20 @@ module OmniAuth
29
25
  include Singleton
30
26
 
31
27
  def self.default_logger
32
- logger = Logger.new(STDOUT)
28
+ logger = Logger.new($stdout)
33
29
  logger.progname = 'omniauth'
34
30
  logger
35
31
  end
36
32
 
37
- def self.defaults # rubocop:disable MethodLength
33
+ def self.defaults # rubocop:disable Metrics/MethodLength
38
34
  @defaults ||= {
39
35
  :camelizations => {},
40
36
  :path_prefix => '/auth',
41
- :on_failure => OmniAuth::FailureEndpoint,
37
+ :on_failure => FailureEndpoint,
42
38
  :failure_raise_out_environments => ['development'],
43
- :request_validation_phase => OmniAuth::AuthenticityTokenProtection,
39
+ :request_validation_phase => AuthenticityTokenProtection,
44
40
  :before_request_phase => nil,
41
+ :after_request_phase => nil,
45
42
  :before_callback_phase => nil,
46
43
  :before_options_phase => nil,
47
44
  :form_css => Form::DEFAULT_CSS,
@@ -49,12 +46,13 @@ module OmniAuth
49
46
  :logger => default_logger,
50
47
  :allowed_request_methods => %i[post],
51
48
  :mock_auth => {:default => AuthHash.new('provider' => 'default', 'uid' => '1234', 'info' => {'name' => 'Example User'})},
52
- :silence_get_warning => false
49
+ :silence_get_warning => false,
50
+ :allowed_hosts => nil
53
51
  }
54
52
  end
55
53
 
56
54
  def initialize
57
- self.class.defaults.each_pair { |k, v| send("#{k}=", v) }
55
+ self.class.defaults.each_pair { |k, v| public_send("#{k}=", v) }
58
56
  end
59
57
 
60
58
  def on_failure(&block)
@@ -97,19 +95,28 @@ module OmniAuth
97
95
  end
98
96
  end
99
97
 
98
+ def after_request_phase(&block)
99
+ if block_given?
100
+ @after_request_phase = block
101
+ else
102
+ @after_request_phase
103
+ end
104
+ end
105
+
100
106
  def add_mock(provider, original = {})
101
107
  # Create key-stringified new hash from given auth hash
102
- mock = {}
108
+ mock = {} #: Hash[String, untyped]
103
109
  original.each_pair do |key, val|
104
110
  mock[key.to_s] = if val.is_a? Hash
105
- Hash[val.each_pair { |k, v| [k.to_s, v] }]
111
+ val.transform_keys(&:to_s)
106
112
  else
107
113
  val
108
114
  end
109
115
  end
110
116
 
111
117
  # Merge with the default mock and ensure provider is correct.
112
- mock = mock_auth[:default].dup.merge(mock)
118
+ default = mock_auth.fetch(:default) #: AuthHash
119
+ mock = default.merge(mock)
113
120
  mock['provider'] = provider.to_s
114
121
 
115
122
  # Add it to the mocks.
@@ -126,9 +133,10 @@ module OmniAuth
126
133
  camelizations[name.to_s] = camelized.to_s
127
134
  end
128
135
 
129
- attr_writer :on_failure, :before_callback_phase, :before_options_phase, :before_request_phase, :request_validation_phase
136
+ attr_writer :on_failure, :before_callback_phase, :before_options_phase, :before_request_phase, :after_request_phase, :request_validation_phase
130
137
  attr_accessor :failure_raise_out_environments, :path_prefix, :allowed_request_methods, :form_css,
131
- :test_mode, :mock_auth, :full_host, :camelizations, :logger, :silence_get_warning
138
+ :test_mode, :mock_auth, :full_host, :camelizations, :logger, :silence_get_warning,
139
+ :allowed_hosts
132
140
  end
133
141
 
134
142
  def self.config
@@ -148,7 +156,7 @@ module OmniAuth
148
156
  end
149
157
 
150
158
  module Utils
151
- module_function # rubocop:disable Layout/IndentationWidth
159
+ module_function
152
160
 
153
161
  def form_css
154
162
  "<style type='text/css'>#{OmniAuth.config.form_css}</style>"
@@ -157,25 +165,29 @@ module OmniAuth
157
165
  def deep_merge(hash, other_hash)
158
166
  target = hash.dup
159
167
 
160
- other_hash.each_key do |key|
161
- if other_hash[key].is_a?(::Hash) && hash[key].is_a?(::Hash)
162
- target[key] = deep_merge(target[key], other_hash[key])
163
- next
164
- end
165
-
166
- target[key] = other_hash[key]
168
+ other_hash.each_pair do |key, value|
169
+ current = hash[key]
170
+ target[key] = current.is_a?(Hash) && value.is_a?(Hash) ? deep_merge(current, value) : value
167
171
  end
168
172
 
169
173
  target
170
174
  end
171
175
 
172
176
  def camelize(word, first_letter_in_uppercase = true)
173
- return OmniAuth.config.camelizations[word.to_s] if OmniAuth.config.camelizations[word.to_s]
177
+ camelized = OmniAuth.config.camelizations[word.to_s]
178
+ return camelized if camelized
174
179
 
175
180
  if first_letter_in_uppercase
176
- word.to_s.gsub(%r{/(.?)}) { '::' + Regexp.last_match[1].upcase }.gsub(/(^|_)(.)/) { Regexp.last_match[2].upcase }
181
+ namespaced = word.to_s.gsub(%r{/(.?)}) do
182
+ char = Regexp.last_match(1) #: String
183
+ "::#{char.upcase}"
184
+ end
185
+ namespaced.gsub(/(\A|_)(.)/) do
186
+ char = Regexp.last_match(2) #: String
187
+ char.upcase
188
+ end
177
189
  else
178
- camelize(word).tap { |w| w[0] = w[0].downcase }
190
+ camelize(word).tap { |w| w[0] = w[0].to_s.downcase }
179
191
  end
180
192
  end
181
193
  end
data/sig/manifest.yaml ADDED
@@ -0,0 +1,5 @@
1
+ # Standard libraries these signatures refer to, which RBS loads for anyone
2
+ # using them.
3
+ dependencies:
4
+ - name: logger
5
+ - name: singleton