omniauth 1.2.2 → 2.1.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.
- checksums.yaml +5 -5
- data/.github/FUNDING.yml +2 -0
- data/.github/ISSUE_TEMPLATE.md +20 -0
- data/.github/workflows/main.yml +89 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +43 -55
- data/Gemfile +15 -20
- data/LICENSE.md +1 -1
- data/README.md +141 -44
- data/Rakefile +38 -2
- data/SECURITY.md +17 -0
- data/lib/omniauth/auth_hash.rb +7 -8
- data/lib/omniauth/authenticity_token_protection.rb +32 -0
- data/lib/omniauth/builder.rb +5 -20
- data/lib/omniauth/failure_endpoint.rb +13 -2
- data/lib/omniauth/form.css +1 -1
- data/lib/omniauth/form.rb +3 -2
- data/lib/omniauth/key_store.rb +22 -0
- data/lib/omniauth/strategies/developer.rb +2 -2
- data/lib/omniauth/strategy.rb +141 -67
- data/lib/omniauth/test/strategy_test_case.rb +2 -2
- data/lib/omniauth/version.rb +1 -1
- data/lib/omniauth.rb +30 -22
- data/omniauth.gemspec +11 -8
- metadata +51 -45
- data/.gemtest +0 -0
- data/.travis.yml +0 -37
- data/Gemfile.rack-1.3.x +0 -25
- data/Guardfile +0 -10
- data/spec/helper.rb +0 -55
- data/spec/omniauth/auth_hash_spec.rb +0 -111
- data/spec/omniauth/builder_spec.rb +0 -50
- data/spec/omniauth/failure_endpoint_spec.rb +0 -58
- data/spec/omniauth/form_spec.rb +0 -23
- data/spec/omniauth/strategies/developer_spec.rb +0 -73
- data/spec/omniauth/strategy_spec.rb +0 -768
- data/spec/omniauth_spec.rb +0 -145
data/lib/omniauth/version.rb
CHANGED
data/lib/omniauth.rb
CHANGED
@@ -15,6 +15,7 @@ module OmniAuth
|
|
15
15
|
autoload :Form, 'omniauth/form'
|
16
16
|
autoload :AuthHash, 'omniauth/auth_hash'
|
17
17
|
autoload :FailureEndpoint, 'omniauth/failure_endpoint'
|
18
|
+
autoload :AuthenticityTokenProtection, 'omniauth/authenticity_token_protection'
|
18
19
|
|
19
20
|
def self.strategies
|
20
21
|
@strategies ||= []
|
@@ -29,20 +30,22 @@ module OmniAuth
|
|
29
30
|
logger
|
30
31
|
end
|
31
32
|
|
32
|
-
def self.defaults
|
33
|
+
def self.defaults # rubocop:disable MethodLength
|
33
34
|
@defaults ||= {
|
34
35
|
:camelizations => {},
|
35
36
|
:path_prefix => '/auth',
|
36
37
|
:on_failure => OmniAuth::FailureEndpoint,
|
37
38
|
:failure_raise_out_environments => ['development'],
|
39
|
+
:request_validation_phase => OmniAuth::AuthenticityTokenProtection,
|
38
40
|
:before_request_phase => nil,
|
39
41
|
:before_callback_phase => nil,
|
40
42
|
:before_options_phase => nil,
|
41
43
|
:form_css => Form::DEFAULT_CSS,
|
42
44
|
:test_mode => false,
|
43
45
|
:logger => default_logger,
|
44
|
-
:allowed_request_methods => [
|
45
|
-
:mock_auth => {:default => AuthHash.new('provider' => 'default', 'uid' => '1234', 'info' => {'name' => 'Example User'})}
|
46
|
+
:allowed_request_methods => %i[post],
|
47
|
+
:mock_auth => {:default => AuthHash.new('provider' => 'default', 'uid' => '1234', 'info' => {'name' => 'Example User'})},
|
48
|
+
:silence_get_warning => false
|
46
49
|
}
|
47
50
|
end
|
48
51
|
|
@@ -74,6 +77,14 @@ module OmniAuth
|
|
74
77
|
end
|
75
78
|
end
|
76
79
|
|
80
|
+
def request_validation_phase(&block)
|
81
|
+
if block_given?
|
82
|
+
@request_validation_phase = block
|
83
|
+
else
|
84
|
+
@request_validation_phase
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
77
88
|
def before_request_phase(&block)
|
78
89
|
if block_given?
|
79
90
|
@before_request_phase = block
|
@@ -82,19 +93,15 @@ module OmniAuth
|
|
82
93
|
end
|
83
94
|
end
|
84
95
|
|
85
|
-
def add_mock(provider,
|
86
|
-
#
|
87
|
-
mock
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
95
|
-
else
|
96
|
-
next
|
97
|
-
end
|
96
|
+
def add_mock(provider, original = {})
|
97
|
+
# Create key-stringified new hash from given auth hash
|
98
|
+
mock = {}
|
99
|
+
original.each_pair do |key, val|
|
100
|
+
mock[key.to_s] = if val.is_a? Hash
|
101
|
+
Hash[val.each_pair { |k, v| [k.to_s, v] }]
|
102
|
+
else
|
103
|
+
val
|
104
|
+
end
|
98
105
|
end
|
99
106
|
|
100
107
|
# Merge with the default mock and ensure provider is correct.
|
@@ -115,8 +122,9 @@ module OmniAuth
|
|
115
122
|
camelizations[name.to_s] = camelized.to_s
|
116
123
|
end
|
117
124
|
|
118
|
-
attr_writer :on_failure, :before_callback_phase, :before_options_phase, :before_request_phase
|
119
|
-
attr_accessor :failure_raise_out_environments, :path_prefix, :allowed_request_methods, :form_css,
|
125
|
+
attr_writer :on_failure, :before_callback_phase, :before_options_phase, :before_request_phase, :request_validation_phase
|
126
|
+
attr_accessor :failure_raise_out_environments, :path_prefix, :allowed_request_methods, :form_css,
|
127
|
+
:test_mode, :mock_auth, :full_host, :camelizations, :logger, :silence_get_warning
|
120
128
|
end
|
121
129
|
|
122
130
|
def self.config
|
@@ -136,7 +144,7 @@ module OmniAuth
|
|
136
144
|
end
|
137
145
|
|
138
146
|
module Utils
|
139
|
-
|
147
|
+
module_function # rubocop:disable Layout/IndentationWidth
|
140
148
|
|
141
149
|
def form_css
|
142
150
|
"<style type='text/css'>#{OmniAuth.config.form_css}</style>"
|
@@ -145,7 +153,7 @@ module OmniAuth
|
|
145
153
|
def deep_merge(hash, other_hash)
|
146
154
|
target = hash.dup
|
147
155
|
|
148
|
-
other_hash.
|
156
|
+
other_hash.each_key do |key|
|
149
157
|
if other_hash[key].is_a?(::Hash) && hash[key].is_a?(::Hash)
|
150
158
|
target[key] = deep_merge(target[key], other_hash[key])
|
151
159
|
next
|
@@ -161,9 +169,9 @@ module OmniAuth
|
|
161
169
|
return OmniAuth.config.camelizations[word.to_s] if OmniAuth.config.camelizations[word.to_s]
|
162
170
|
|
163
171
|
if first_letter_in_uppercase
|
164
|
-
word.to_s.gsub(
|
172
|
+
word.to_s.gsub(%r{/(.?)}) { '::' + Regexp.last_match[1].upcase }.gsub(/(^|_)(.)/) { Regexp.last_match[2].upcase }
|
165
173
|
else
|
166
|
-
word.
|
174
|
+
camelize(word).tap { |w| w[0] = w[0].downcase }
|
167
175
|
end
|
168
176
|
end
|
169
177
|
end
|
data/omniauth.gemspec
CHANGED
@@ -1,22 +1,25 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'omniauth/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.add_dependency 'hashie', ['>=
|
8
|
-
spec.add_dependency 'rack', '
|
9
|
-
spec.add_development_dependency 'bundler', '~>
|
8
|
+
spec.add_dependency 'hashie', ['>= 3.4.6']
|
9
|
+
spec.add_dependency 'rack', '>= 2.2.3'
|
10
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
11
|
+
spec.add_dependency 'rack-protection'
|
12
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
10
13
|
spec.authors = ['Michael Bleigh', 'Erik Michaels-Ober', 'Tom Milewski']
|
11
14
|
spec.description = 'A generalized Rack framework for multiple-provider authentication.'
|
12
15
|
spec.email = ['michael@intridea.com', 'sferik@gmail.com', 'tmilewski@gmail.com']
|
13
|
-
spec.files = `git ls-files`.split(
|
14
|
-
spec.homepage = '
|
15
|
-
spec.licenses = %w
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.start_with?('spec/') }
|
17
|
+
spec.homepage = 'https://github.com/omniauth/omniauth'
|
18
|
+
spec.licenses = %w[MIT]
|
16
19
|
spec.name = 'omniauth'
|
17
|
-
spec.require_paths = %w
|
20
|
+
spec.require_paths = %w[lib]
|
18
21
|
spec.required_rubygems_version = '>= 1.3.5'
|
22
|
+
spec.required_ruby_version = '>= 2.2'
|
19
23
|
spec.summary = spec.description
|
20
|
-
spec.test_files = spec.files.grep(/^spec\//)
|
21
24
|
spec.version = OmniAuth::VERSION
|
22
25
|
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
8
8
|
- Erik Michaels-Ober
|
9
9
|
- Tom Milewski
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2022-04-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: hashie
|
@@ -18,48 +18,70 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
22
|
-
- - "<"
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: '4'
|
21
|
+
version: 3.4.6
|
25
22
|
type: :runtime
|
26
23
|
prerelease: false
|
27
24
|
version_requirements: !ruby/object:Gem::Requirement
|
28
25
|
requirements:
|
29
26
|
- - ">="
|
30
27
|
- !ruby/object:Gem::Version
|
31
|
-
version:
|
32
|
-
- - "<"
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '4'
|
28
|
+
version: 3.4.6
|
35
29
|
- !ruby/object:Gem::Dependency
|
36
30
|
name: rack
|
37
31
|
requirement: !ruby/object:Gem::Requirement
|
38
32
|
requirements:
|
39
|
-
- - "
|
33
|
+
- - ">="
|
40
34
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
35
|
+
version: 2.2.3
|
42
36
|
type: :runtime
|
43
37
|
prerelease: false
|
44
38
|
version_requirements: !ruby/object:Gem::Requirement
|
45
39
|
requirements:
|
46
|
-
- - "
|
40
|
+
- - ">="
|
47
41
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
42
|
+
version: 2.2.3
|
49
43
|
- !ruby/object:Gem::Dependency
|
50
44
|
name: bundler
|
51
45
|
requirement: !ruby/object:Gem::Requirement
|
52
46
|
requirements:
|
53
47
|
- - "~>"
|
54
48
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
49
|
+
version: '2.0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '2.0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: rack-protection
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
type: :runtime
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: rake
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '12.0'
|
56
78
|
type: :development
|
57
79
|
prerelease: false
|
58
80
|
version_requirements: !ruby/object:Gem::Requirement
|
59
81
|
requirements:
|
60
82
|
- - "~>"
|
61
83
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
84
|
+
version: '12.0'
|
63
85
|
description: A generalized Rack framework for multiple-provider authentication.
|
64
86
|
email:
|
65
87
|
- michael@intridea.com
|
@@ -69,24 +91,26 @@ executables: []
|
|
69
91
|
extensions: []
|
70
92
|
extra_rdoc_files: []
|
71
93
|
files:
|
72
|
-
- ".
|
94
|
+
- ".github/FUNDING.yml"
|
95
|
+
- ".github/ISSUE_TEMPLATE.md"
|
96
|
+
- ".github/workflows/main.yml"
|
73
97
|
- ".gitignore"
|
74
98
|
- ".rspec"
|
75
99
|
- ".rubocop.yml"
|
76
|
-
- ".travis.yml"
|
77
100
|
- ".yardopts"
|
78
101
|
- Gemfile
|
79
|
-
- Gemfile.rack-1.3.x
|
80
|
-
- Guardfile
|
81
102
|
- LICENSE.md
|
82
103
|
- README.md
|
83
104
|
- Rakefile
|
105
|
+
- SECURITY.md
|
84
106
|
- lib/omniauth.rb
|
85
107
|
- lib/omniauth/auth_hash.rb
|
108
|
+
- lib/omniauth/authenticity_token_protection.rb
|
86
109
|
- lib/omniauth/builder.rb
|
87
110
|
- lib/omniauth/failure_endpoint.rb
|
88
111
|
- lib/omniauth/form.css
|
89
112
|
- lib/omniauth/form.rb
|
113
|
+
- lib/omniauth/key_store.rb
|
90
114
|
- lib/omniauth/strategies/developer.rb
|
91
115
|
- lib/omniauth/strategy.rb
|
92
116
|
- lib/omniauth/test.rb
|
@@ -95,19 +119,11 @@ files:
|
|
95
119
|
- lib/omniauth/test/strategy_test_case.rb
|
96
120
|
- lib/omniauth/version.rb
|
97
121
|
- omniauth.gemspec
|
98
|
-
|
99
|
-
- spec/omniauth/auth_hash_spec.rb
|
100
|
-
- spec/omniauth/builder_spec.rb
|
101
|
-
- spec/omniauth/failure_endpoint_spec.rb
|
102
|
-
- spec/omniauth/form_spec.rb
|
103
|
-
- spec/omniauth/strategies/developer_spec.rb
|
104
|
-
- spec/omniauth/strategy_spec.rb
|
105
|
-
- spec/omniauth_spec.rb
|
106
|
-
homepage: http://github.com/intridea/omniauth
|
122
|
+
homepage: https://github.com/omniauth/omniauth
|
107
123
|
licenses:
|
108
124
|
- MIT
|
109
125
|
metadata: {}
|
110
|
-
post_install_message:
|
126
|
+
post_install_message:
|
111
127
|
rdoc_options: []
|
112
128
|
require_paths:
|
113
129
|
- lib
|
@@ -115,25 +131,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
131
|
requirements:
|
116
132
|
- - ">="
|
117
133
|
- !ruby/object:Gem::Version
|
118
|
-
version: '
|
134
|
+
version: '2.2'
|
119
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
136
|
requirements:
|
121
137
|
- - ">="
|
122
138
|
- !ruby/object:Gem::Version
|
123
139
|
version: 1.3.5
|
124
140
|
requirements: []
|
125
|
-
|
126
|
-
|
127
|
-
signing_key:
|
141
|
+
rubygems_version: 3.2.32
|
142
|
+
signing_key:
|
128
143
|
specification_version: 4
|
129
144
|
summary: A generalized Rack framework for multiple-provider authentication.
|
130
|
-
test_files:
|
131
|
-
- spec/helper.rb
|
132
|
-
- spec/omniauth/auth_hash_spec.rb
|
133
|
-
- spec/omniauth/builder_spec.rb
|
134
|
-
- spec/omniauth/failure_endpoint_spec.rb
|
135
|
-
- spec/omniauth/form_spec.rb
|
136
|
-
- spec/omniauth/strategies/developer_spec.rb
|
137
|
-
- spec/omniauth/strategy_spec.rb
|
138
|
-
- spec/omniauth_spec.rb
|
139
|
-
has_rdoc:
|
145
|
+
test_files: []
|
data/.gemtest
DELETED
File without changes
|
data/.travis.yml
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
bundler_args: --without development
|
2
|
-
gemfile:
|
3
|
-
- Gemfile
|
4
|
-
- Gemfile.rack-1.3.x
|
5
|
-
language: ruby
|
6
|
-
rvm:
|
7
|
-
- 1.8.7
|
8
|
-
- 1.9.2
|
9
|
-
- 1.9.3
|
10
|
-
- 2.0.0
|
11
|
-
- 2.1.0
|
12
|
-
- rbx-2
|
13
|
-
- ruby-head
|
14
|
-
matrix:
|
15
|
-
include:
|
16
|
-
- rvm: jruby-18mode
|
17
|
-
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
18
|
-
gemfile: Gemfile
|
19
|
-
- rvm: jruby-18mode
|
20
|
-
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
21
|
-
gemfile: Gemfile.rack-1.3.x
|
22
|
-
- rvm: jruby-19mode
|
23
|
-
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
24
|
-
gemfile: Gemfile
|
25
|
-
- rvm: jruby-19mode
|
26
|
-
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
27
|
-
gemfile: Gemfile.rack-1.3.x
|
28
|
-
- rvm: jruby-head
|
29
|
-
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
30
|
-
gemfile: Gemfile
|
31
|
-
- rvm: jruby-head
|
32
|
-
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
33
|
-
gemfile: Gemfile.rack-1.3.x
|
34
|
-
allow_failures:
|
35
|
-
- rvm: jruby-head
|
36
|
-
- rvm: ruby-head
|
37
|
-
fast_finish: true
|
data/Gemfile.rack-1.3.x
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
gem 'jruby-openssl', :platforms => :jruby
|
4
|
-
gem 'rack', '~> 1.3.0'
|
5
|
-
gem 'rake'
|
6
|
-
gem 'yard'
|
7
|
-
|
8
|
-
group :test do
|
9
|
-
gem 'coveralls', :require => false
|
10
|
-
gem 'json', '>= 1.8.1', :platforms => [:jruby, :rbx, :ruby_18, :ruby_19]
|
11
|
-
gem 'mime-types', '~> 1.25', :platforms => [:jruby, :ruby_18]
|
12
|
-
gem 'rack-test'
|
13
|
-
gem 'rest-client', '~> 1.6.0', :platforms => [:jruby, :ruby_18]
|
14
|
-
gem 'rspec', '>= 2.14'
|
15
|
-
gem 'rubocop', '>= 0.23', :platforms => [:ruby_19, :ruby_20, :ruby_21]
|
16
|
-
gem 'simplecov', :require => false
|
17
|
-
end
|
18
|
-
|
19
|
-
platforms :rbx do
|
20
|
-
gem 'racc'
|
21
|
-
gem 'rubinius-coverage', '~> 2.0'
|
22
|
-
gem 'rubysl', '~> 2.0'
|
23
|
-
end
|
24
|
-
|
25
|
-
gemspec
|
data/Guardfile
DELETED
data/spec/helper.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'simplecov'
|
2
|
-
require 'coveralls'
|
3
|
-
|
4
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
-
SimpleCov::Formatter::HTMLFormatter,
|
6
|
-
Coveralls::SimpleCov::Formatter
|
7
|
-
]
|
8
|
-
SimpleCov.start do
|
9
|
-
add_filter '/spec/'
|
10
|
-
minimum_coverage(93.05)
|
11
|
-
end
|
12
|
-
|
13
|
-
require 'rspec'
|
14
|
-
require 'rack/test'
|
15
|
-
require 'omniauth'
|
16
|
-
require 'omniauth/test'
|
17
|
-
|
18
|
-
OmniAuth.config.logger = Logger.new('/dev/null')
|
19
|
-
|
20
|
-
RSpec.configure do |config|
|
21
|
-
config.include Rack::Test::Methods
|
22
|
-
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
23
|
-
config.expect_with :rspec do |c|
|
24
|
-
c.syntax = :expect
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class ExampleStrategy
|
29
|
-
include OmniAuth::Strategy
|
30
|
-
attr_reader :last_env
|
31
|
-
option :name, 'test'
|
32
|
-
|
33
|
-
def call(env)
|
34
|
-
self.call!(env)
|
35
|
-
end
|
36
|
-
|
37
|
-
def initialize(*args, &block)
|
38
|
-
super
|
39
|
-
@fail = nil
|
40
|
-
end
|
41
|
-
|
42
|
-
def request_phase
|
43
|
-
@fail = fail!(options[:failure]) if options[:failure]
|
44
|
-
@last_env = env
|
45
|
-
return @fail if @fail
|
46
|
-
fail('Request Phase')
|
47
|
-
end
|
48
|
-
|
49
|
-
def callback_phase
|
50
|
-
@fail = fail!(options[:failure]) if options[:failure]
|
51
|
-
@last_env = env
|
52
|
-
return @fail if @fail
|
53
|
-
fail('Callback Phase')
|
54
|
-
end
|
55
|
-
end
|
@@ -1,111 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe OmniAuth::AuthHash do
|
4
|
-
subject { OmniAuth::AuthHash.new }
|
5
|
-
it 'converts a supplied info key into an InfoHash object' do
|
6
|
-
subject.info = {:first_name => 'Awesome'}
|
7
|
-
expect(subject.info).to be_kind_of(OmniAuth::AuthHash::InfoHash)
|
8
|
-
expect(subject.info.first_name).to eq('Awesome')
|
9
|
-
end
|
10
|
-
|
11
|
-
describe '#valid?' do
|
12
|
-
subject { OmniAuth::AuthHash.new(:uid => '123', :provider => 'example', :info => {:name => 'Steven'}) }
|
13
|
-
|
14
|
-
it 'is valid with the right parameters' do
|
15
|
-
expect(subject).to be_valid
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'requires a uid' do
|
19
|
-
subject.uid = nil
|
20
|
-
expect(subject).not_to be_valid
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'requires a provider' do
|
24
|
-
subject.provider = nil
|
25
|
-
expect(subject).not_to be_valid
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'requires a name in the user info hash' do
|
29
|
-
subject.info.name = nil
|
30
|
-
expect(subject).not_to be_valid
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe '#name' do
|
35
|
-
subject do
|
36
|
-
OmniAuth::AuthHash.new(
|
37
|
-
:info => {
|
38
|
-
:name => 'Phillip J. Fry',
|
39
|
-
:first_name => 'Phillip',
|
40
|
-
:last_name => 'Fry',
|
41
|
-
:nickname => 'meatbag',
|
42
|
-
:email => 'fry@planetexpress.com',
|
43
|
-
}
|
44
|
-
)
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'defaults to the name key' do
|
48
|
-
expect(subject.info.name).to eq('Phillip J. Fry')
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'falls back to go to first_name last_name concatenation' do
|
52
|
-
subject.info.name = nil
|
53
|
-
expect(subject.info.name).to eq('Phillip Fry')
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'displays only a first or last name if only that is available' do
|
57
|
-
subject.info.name = nil
|
58
|
-
subject.info.first_name = nil
|
59
|
-
expect(subject.info.name).to eq('Fry')
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'displays the nickname if no name, first, or last is available' do
|
63
|
-
subject.info.name = nil
|
64
|
-
%w(first_name last_name).each { |k| subject.info[k] = nil }
|
65
|
-
expect(subject.info.name).to eq('meatbag')
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'displays the email if no name, first, last, or nick is available' do
|
69
|
-
subject.info.name = nil
|
70
|
-
%w(first_name last_name nickname).each { |k| subject.info[k] = nil }
|
71
|
-
expect(subject.info.name).to eq('fry@planetexpress.com')
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe '#to_hash' do
|
76
|
-
subject { OmniAuth::AuthHash.new(:uid => '123', :provider => 'test', :name => 'Example User') }
|
77
|
-
let(:hash) { subject.to_hash }
|
78
|
-
|
79
|
-
it 'is a plain old hash' do
|
80
|
-
expect(hash.class).to eq(::Hash)
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'has string keys' do
|
84
|
-
expect(hash.keys).to be_include('uid')
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'converts an info hash as well' do
|
88
|
-
subject.info = {:first_name => 'Example', :last_name => 'User'}
|
89
|
-
expect(subject.info.class).to eq(OmniAuth::AuthHash::InfoHash)
|
90
|
-
expect(subject.to_hash['info'].class).to eq(::Hash)
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'supplies the calculated name in the converted hash' do
|
94
|
-
subject.info = {:first_name => 'Examplar', :last_name => 'User'}
|
95
|
-
expect(hash['info']['name']).to eq('Examplar User')
|
96
|
-
end
|
97
|
-
|
98
|
-
it "does not pollute the URL hash with 'name' etc" do
|
99
|
-
subject.info = {'urls' => {'Homepage' => 'http://homepage.com'}}
|
100
|
-
expect(subject.to_hash['info']['urls']).to eq('Homepage' => 'http://homepage.com')
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe OmniAuth::AuthHash::InfoHash do
|
105
|
-
describe '#valid?' do
|
106
|
-
it 'is valid if there is a name' do
|
107
|
-
expect(OmniAuth::AuthHash::InfoHash.new(:name => 'Awesome')).to be_valid
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe OmniAuth::Builder do
|
4
|
-
describe '#provider' do
|
5
|
-
it 'translates a symbol to a constant' do
|
6
|
-
expect(OmniAuth::Strategies).to receive(:const_get).with('MyStrategy').and_return(Class.new)
|
7
|
-
OmniAuth::Builder.new(nil) do
|
8
|
-
provider :my_strategy
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'accepts a class' do
|
13
|
-
class ExampleClass; end
|
14
|
-
|
15
|
-
expect do
|
16
|
-
OmniAuth::Builder.new(nil) do
|
17
|
-
provider ::ExampleClass
|
18
|
-
end
|
19
|
-
end.not_to raise_error
|
20
|
-
end
|
21
|
-
|
22
|
-
it "raises a helpful LoadError message if it can't find the class" do
|
23
|
-
expect do
|
24
|
-
OmniAuth::Builder.new(nil) do
|
25
|
-
provider :lorax
|
26
|
-
end
|
27
|
-
end.to raise_error(LoadError, 'Could not find matching strategy for :lorax. You may need to install an additional gem (such as omniauth-lorax).')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe '#options' do
|
32
|
-
it 'merges provided options in' do
|
33
|
-
k = Class.new
|
34
|
-
b = OmniAuth::Builder.new(nil)
|
35
|
-
expect(b).to receive(:use).with(k, :foo => 'bar', :baz => 'tik')
|
36
|
-
|
37
|
-
b.options :foo => 'bar'
|
38
|
-
b.provider k, :baz => 'tik'
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'adds an argument if no options are provided' do
|
42
|
-
k = Class.new
|
43
|
-
b = OmniAuth::Builder.new(nil)
|
44
|
-
expect(b).to receive(:use).with(k, :foo => 'bar')
|
45
|
-
|
46
|
-
b.options :foo => 'bar'
|
47
|
-
b.provider k
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|