omniauth-google-oauth2 0.1.12 → 0.1.13
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.
@@ -19,6 +19,10 @@ module OmniAuth
|
|
19
19
|
def authorize_params
|
20
20
|
base_scope_url = "https://www.googleapis.com/auth/"
|
21
21
|
super.tap do |params|
|
22
|
+
# Read the params if passed directly to omniauth_authorize_path
|
23
|
+
%w(scope approval_prompt access_type state hd).each do |k|
|
24
|
+
params[k.to_sym] = request.params[k] unless [nil, ''].include?(request.params[k])
|
25
|
+
end
|
22
26
|
scopes = (params[:scope] || DEFAULT_SCOPE).split(",")
|
23
27
|
scopes.map! { |s| s =~ /^https?:\/\// ? s : "#{base_scope_url}#{s}" }
|
24
28
|
params[:scope] = scopes.join(' ')
|
@@ -26,12 +30,8 @@ module OmniAuth
|
|
26
30
|
# http://googlecode.blogspot.com/2011/10/upcoming-changes-to-oauth-20-endpoint.html
|
27
31
|
params[:access_type] = 'offline' if params[:access_type].nil?
|
28
32
|
params[:approval_prompt] = 'force' if params[:approval_prompt].nil?
|
29
|
-
# allow overriding approval_prompt on the request itself
|
30
|
-
params[:approval_prompt] = request.params['approval_prompt'] if request_has_approval_prompt
|
31
|
-
# hd ("Hosted Domain") can be set to a Google Apps domain to force a login to that domain
|
32
|
-
params[:hd] = request.params['hd'] if request.params['hd']
|
33
33
|
# Override the state per request
|
34
|
-
session['omniauth.state'] = params[:state]
|
34
|
+
session['omniauth.state'] = params[:state] if request.params['state']
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -40,39 +40,95 @@ describe OmniAuth::Strategies::GoogleOauth2 do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
describe '#callback_path' do
|
43
|
-
it
|
43
|
+
it 'has the correct callback path' do
|
44
44
|
subject.callback_path.should eq('/auth/google_oauth2/callback')
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
describe '#authorize_params' do
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
%w(approval_prompt access_type state hd).each do |k|
|
50
|
+
it "should set the #{k} authorize option dynamically in the request" do
|
51
|
+
@options = {k.to_sym => ''}
|
52
|
+
subject.stub(:request) { double('Request', {:params => { k => 'something' }, :env => {}}) }
|
53
|
+
subject.authorize_params[k].should eq('something')
|
54
|
+
end
|
52
55
|
end
|
53
56
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
+
describe 'scope' do
|
58
|
+
it 'should expand scope shortcuts' do
|
59
|
+
@options = { :authorize_options => [:scope], :scope => 'userinfo.email'}
|
60
|
+
subject.authorize_params['scope'].should eq('https://www.googleapis.com/auth/userinfo.email')
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should leave full scopes as is' do
|
64
|
+
@options = { :authorize_options => [:scope], :scope => 'https://www.googleapis.com/auth/userinfo.profile'}
|
65
|
+
subject.authorize_params['scope'].should eq('https://www.googleapis.com/auth/userinfo.profile')
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should join scopes' do
|
69
|
+
@options = { :authorize_options => [:scope], :scope => 'userinfo.profile,userinfo.email'}
|
70
|
+
subject.authorize_params['scope'].should eq('https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email')
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should set default scope to userinfo.email,userinfo.profile' do
|
74
|
+
@options = { :authorize_options => [:scope]}
|
75
|
+
subject.authorize_params['scope'].should eq('https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile')
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should dynamically set the scope in the request' do
|
79
|
+
@options = {:scope => 'http://example.com'}
|
80
|
+
subject.stub(:request) { double('Request', {:params => { 'scope' => 'userinfo.email' }, :env => {}}) }
|
81
|
+
subject.authorize_params['scope'].should eq('https://www.googleapis.com/auth/userinfo.email')
|
82
|
+
end
|
57
83
|
end
|
58
84
|
|
59
|
-
|
60
|
-
|
61
|
-
|
85
|
+
describe 'approval_prompt' do
|
86
|
+
it 'should set the approval_prompt parameter if present' do
|
87
|
+
@options = {:approval_prompt => 'prompt'}
|
88
|
+
subject.authorize_params['approval_prompt'].should eq('prompt')
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should default to "force"' do
|
92
|
+
@options = {}
|
93
|
+
subject.authorize_params['approval_prompt'].should eq('force')
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe 'access_type' do
|
98
|
+
it 'should set the access_type parameter if present' do
|
99
|
+
@options = {:access_type => 'type'}
|
100
|
+
subject.authorize_params['access_type'].should eq('type')
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should default to "offline"' do
|
104
|
+
@options = {}
|
105
|
+
subject.authorize_params['access_type'].should eq('offline')
|
106
|
+
end
|
62
107
|
end
|
63
108
|
|
64
|
-
|
65
|
-
|
66
|
-
|
109
|
+
describe 'state' do
|
110
|
+
it 'should set the state parameter' do
|
111
|
+
@options = {:state => 'some_state'}
|
112
|
+
subject.authorize_params['state'].should eq('some_state')
|
113
|
+
subject.session['omniauth.state'].should eq('some_state')
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should set the omniauth.state dynamically' do
|
117
|
+
subject.stub(:request) { double('Request', {:params => { 'state' => 'some_state' }, :env => {}}) }
|
118
|
+
subject.authorize_params['state'].should eq('some_state')
|
119
|
+
subject.session['omniauth.state'].should eq('some_state')
|
120
|
+
end
|
67
121
|
end
|
68
122
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
123
|
+
describe 'hd' do
|
124
|
+
it 'should set the hd (hosted domain) parameter if present' do
|
125
|
+
@options = {:hd => 'example.com'}
|
126
|
+
subject.authorize_params['hd'].should eq('example.com')
|
127
|
+
end
|
74
128
|
end
|
129
|
+
end
|
75
130
|
|
131
|
+
describe 'raw info' do
|
76
132
|
it 'should include raw_info in extras hash by default' do
|
77
133
|
subject.stub(:raw_info) { { :foo => 'bar' } }
|
78
134
|
subject.extra[:raw_info].should eq({ :foo => 'bar' })
|
@@ -82,23 +138,5 @@ describe OmniAuth::Strategies::GoogleOauth2 do
|
|
82
138
|
@options = { :skip_info => true }
|
83
139
|
subject.extra.should_not have_key(:raw_info)
|
84
140
|
end
|
85
|
-
|
86
|
-
it 'should set the state parameter' do
|
87
|
-
@options = {:state => "some_state"}
|
88
|
-
subject.authorize_params['state'].should eq('some_state')
|
89
|
-
subject.session['omniauth.state'].should eq('some_state')
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'should set the state parameter dynamically' do
|
93
|
-
subject.stub(:request) { double('Request', {:params => { 'state' => 'some_state' }, :env => {}}) }
|
94
|
-
subject.authorize_params['state'].should eq('some_state')
|
95
|
-
subject.session['omniauth.state'].should eq('some_state')
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'should set the hd (hosted domain) parameter if present' do
|
99
|
-
@options = {:hd => "example.com"}
|
100
|
-
subject.authorize_params['hd'].should eq('example.com')
|
101
|
-
end
|
102
141
|
end
|
103
|
-
|
104
142
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-google-oauth2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-07-
|
13
|
+
date: 2012-07-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: omniauth
|
@@ -112,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
112
112
|
version: '0'
|
113
113
|
segments:
|
114
114
|
- 0
|
115
|
-
hash:
|
115
|
+
hash: 1263356288876244939
|
116
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
117
|
none: false
|
118
118
|
requirements:
|
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
121
|
version: '0'
|
122
122
|
segments:
|
123
123
|
- 0
|
124
|
-
hash:
|
124
|
+
hash: 1263356288876244939
|
125
125
|
requirements: []
|
126
126
|
rubyforge_project:
|
127
127
|
rubygems_version: 1.8.24
|