omniauth-google-oauth2 1.0.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +21 -0
- data/.travis.yml +6 -3
- data/CHANGELOG.md +45 -1
- data/README.md +8 -2
- data/examples/Gemfile +2 -1
- data/examples/config.ru +19 -9
- data/lib/omniauth/google_oauth2/version.rb +1 -1
- data/lib/omniauth/strategies/google_oauth2.rb +31 -9
- data/omniauth-google-oauth2.gemspec +2 -2
- data/spec/omniauth/strategies/google_oauth2_spec.rb +107 -15
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0532842d8362fc36a8797376dc54e09b1d11fa178d462114225eecbe87274785'
|
4
|
+
data.tar.gz: 63b1d0a5a3a6249b77b58cbfa4e696ae18748b59280cb73f36cb98f88abd98c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d6f34a8629057f1f89d613155567d0bb50917648794e64527976ba7ca4c372ed8806fd57bbe5cec55d2d60545ef2e9bd038da80e1101b96642018f1d8226951
|
7
|
+
data.tar.gz: b00da9be3e3f97af0cdfe9a15be3d99126176a26bc21337febb893be88949da0573b4f6a843fbedac3dc982a4fda29ca532b63d3a1272fc8544468b3a42d32aa
|
@@ -0,0 +1,21 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
strategy:
|
9
|
+
matrix:
|
10
|
+
ruby-version: ['2.3', '2.4', '2.5', '2.6', '2.7', '3.0', '3.1']
|
11
|
+
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
15
|
+
uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: ${{ matrix.ruby-version }}
|
18
|
+
bundler-cache: true # 'bundle install' and cache
|
19
|
+
- name: Run specs
|
20
|
+
run: |
|
21
|
+
bundle exec rake
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,50 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## 1.1.1 - 2022-09-05
|
5
|
+
|
6
|
+
### Added
|
7
|
+
- Nothing.
|
8
|
+
|
9
|
+
### Deprecated
|
10
|
+
- Nothing.
|
11
|
+
|
12
|
+
### Removed
|
13
|
+
- Nothing.
|
14
|
+
|
15
|
+
### Fixed
|
16
|
+
- Fixed JWT decoding issue. (Invalid segment encoding) [#431](https://github.com/zquestz/omniauth-google-oauth2/pull/431)
|
17
|
+
|
18
|
+
## 1.1.0 - 2022-09-03
|
19
|
+
|
20
|
+
### Added
|
21
|
+
- `overridable_authorize_options` has been added to restrict overriding authorize_options by request params. [#423](https://github.com/zquestz/omniauth-google-oauth2/pull/423)
|
22
|
+
- Support for oauth2 2.0.x. [#429](https://github.com/zquestz/omniauth-google-oauth2/pull/429)
|
23
|
+
|
24
|
+
### Deprecated
|
25
|
+
- Nothing.
|
26
|
+
|
27
|
+
### Removed
|
28
|
+
- Nothing.
|
29
|
+
|
30
|
+
### Fixed
|
31
|
+
- Nothing.
|
32
|
+
|
33
|
+
## 1.0.1 - 2022-03-10
|
34
|
+
|
35
|
+
### Added
|
36
|
+
- Output granted scopes in credentials block of the auth hash.
|
37
|
+
- Migrated to GitHub actions.
|
38
|
+
|
39
|
+
### Deprecated
|
40
|
+
- Nothing.
|
41
|
+
|
42
|
+
### Removed
|
43
|
+
- Nothing.
|
44
|
+
|
45
|
+
### Fixed
|
46
|
+
- Overriding the `redirect_uri` via params or JSON request body.
|
47
|
+
|
4
48
|
## 1.0.0 - 2021-03-14
|
5
49
|
|
6
50
|
### Added
|
@@ -10,7 +54,7 @@ All notable changes to this project will be documented in this file.
|
|
10
54
|
- Nothing.
|
11
55
|
|
12
56
|
### Removed
|
13
|
-
- Support for Omniauth 1.x
|
57
|
+
- Support for Omniauth 1.x.
|
14
58
|
|
15
59
|
### Fixed
|
16
60
|
- Nothing.
|
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/omniauth-google-oauth2.svg)](https://badge.fury.io/rb/omniauth-google-oauth2)
|
2
|
-
[![Build Status](https://travis-ci.org/zquestz/omniauth-google-oauth2.svg)](https://travis-ci.org/zquestz/omniauth-google-oauth2)
|
3
2
|
|
4
3
|
# OmniAuth Google OAuth2 Strategy
|
5
4
|
|
@@ -34,6 +33,7 @@ Here's an example for adding the middleware to a Rails app in `config/initialize
|
|
34
33
|
Rails.application.config.middleware.use OmniAuth::Builder do
|
35
34
|
provider :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET']
|
36
35
|
end
|
36
|
+
OmniAuth.config.allowed_request_methods = %i[get]
|
37
37
|
```
|
38
38
|
|
39
39
|
You can now access the OmniAuth Google OAuth2 URL: `/auth/google_oauth2`
|
@@ -85,13 +85,15 @@ You can configure several options, which you pass in to the `provider` method vi
|
|
85
85
|
|
86
86
|
* `provider_ignores_state`: You will need to set this to `true` when using the `One-time Code Flow` below. In this flow there is no server side redirect that would set the state.
|
87
87
|
|
88
|
+
* `overridable_authorize_options`: By default, all `authorize_options` can be overridden with request parameters. You can restrict the behavior by using this option.
|
89
|
+
|
88
90
|
Here's an example of a possible configuration where the strategy name is changed, the user is asked for extra permissions, the user is always prompted to select their account when logging in and the user's profile picture is returned as a thumbnail:
|
89
91
|
|
90
92
|
```ruby
|
91
93
|
Rails.application.config.middleware.use OmniAuth::Builder do
|
92
94
|
provider :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET'],
|
93
95
|
{
|
94
|
-
scope: '
|
96
|
+
scope: 'email, profile, http://gdata.youtube.com',
|
95
97
|
prompt: 'select_account',
|
96
98
|
image_aspect_ratio: 'square',
|
97
99
|
image_size: 50
|
@@ -217,6 +219,10 @@ end
|
|
217
219
|
For your views you can login using:
|
218
220
|
|
219
221
|
```erb
|
222
|
+
<%# omniauth-google-oauth2 1.0.x uses OmniAuth 2 and requires using HTTP Post to initiate authentication: %>
|
223
|
+
<%= link_to "Sign in with Google", user_google_oauth2_omniauth_authorize_path, method: :post %>
|
224
|
+
|
225
|
+
<%# omniauth-google-oauth2 prior 1.0.0: %>
|
220
226
|
<%= link_to "Sign in with Google", user_google_oauth2_omniauth_authorize_path %>
|
221
227
|
|
222
228
|
<%# Devise prior 4.1.0: %>
|
data/examples/Gemfile
CHANGED
data/examples/config.ru
CHANGED
@@ -19,6 +19,19 @@ OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
|
19
19
|
|
20
20
|
# Main example app for omniauth-google-oauth2
|
21
21
|
class App < Sinatra::Base
|
22
|
+
configure do
|
23
|
+
set :sessions, true
|
24
|
+
set :inline_templates, true
|
25
|
+
end
|
26
|
+
|
27
|
+
use Rack::Session::Cookie, secret: ENV['RACK_COOKIE_SECRET']
|
28
|
+
|
29
|
+
use OmniAuth::Builder do
|
30
|
+
# For additional provider examples please look at 'omni_auth.rb'
|
31
|
+
# The key provider_ignores_state is only for AJAX flows. It is not recommended for normal logins.
|
32
|
+
provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'], access_type: 'offline', prompt: 'consent', provider_ignores_state: true, scope: 'email,profile,calendar'
|
33
|
+
end
|
34
|
+
|
22
35
|
get '/' do
|
23
36
|
<<-HTML
|
24
37
|
<!DOCTYPE html>
|
@@ -73,7 +86,12 @@ class App < Sinatra::Base
|
|
73
86
|
</head>
|
74
87
|
<body>
|
75
88
|
<ul>
|
76
|
-
<li
|
89
|
+
<li>
|
90
|
+
<form method='post' action='/auth/google_oauth2'>
|
91
|
+
<input type="hidden" name="authenticity_token" value="#{request.env['rack.session']['csrf']}">
|
92
|
+
<button type='submit'>Login with Google</button>
|
93
|
+
</form>
|
94
|
+
</li>
|
77
95
|
<li><a href='#' class="googleplus-login">Sign in with Google via AJAX</a></li>
|
78
96
|
</ul>
|
79
97
|
</body>
|
@@ -109,12 +127,4 @@ class App < Sinatra::Base
|
|
109
127
|
end
|
110
128
|
end
|
111
129
|
|
112
|
-
use Rack::Session::Cookie, secret: ENV['RACK_COOKIE_SECRET']
|
113
|
-
|
114
|
-
use OmniAuth::Builder do
|
115
|
-
# For additional provider examples please look at 'omni_auth.rb'
|
116
|
-
# The key provider_ignores_state is only for AJAX flows. It is not recommended for normal logins.
|
117
|
-
provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'], access_type: 'offline', prompt: 'consent', provider_ignores_state: true, scope: 'email,profile,calendar'
|
118
|
-
end
|
119
|
-
|
120
130
|
run App.new
|
@@ -15,13 +15,15 @@ module OmniAuth
|
|
15
15
|
DEFAULT_SCOPE = 'email,profile'
|
16
16
|
USER_INFO_URL = 'https://www.googleapis.com/oauth2/v3/userinfo'
|
17
17
|
IMAGE_SIZE_REGEXP = /(s\d+(-c)?)|(w\d+-h\d+(-c)?)|(w\d+(-c)?)|(h\d+(-c)?)|c/
|
18
|
+
AUTHORIZE_OPTIONS = %i[access_type hd login_hint prompt request_visible_actions scope state redirect_uri include_granted_scopes openid_realm device_id device_name]
|
18
19
|
|
19
20
|
option :name, 'google_oauth2'
|
20
21
|
option :skip_friends, true
|
21
22
|
option :skip_image_info, true
|
22
23
|
option :skip_jwt, false
|
23
24
|
option :jwt_leeway, 60
|
24
|
-
option :authorize_options,
|
25
|
+
option :authorize_options, AUTHORIZE_OPTIONS
|
26
|
+
option :overridable_authorize_options, AUTHORIZE_OPTIONS
|
25
27
|
option :authorized_client_ids, []
|
26
28
|
|
27
29
|
option :client_options,
|
@@ -31,7 +33,7 @@ module OmniAuth
|
|
31
33
|
|
32
34
|
def authorize_params
|
33
35
|
super.tap do |params|
|
34
|
-
options[:authorize_options].each do |k|
|
36
|
+
(options[:authorize_options] & options[:overridable_authorize_options]).each do |k|
|
35
37
|
params[k] = request.params[k.to_s] unless [nil, ''].include?(request.params[k.to_s])
|
36
38
|
end
|
37
39
|
|
@@ -60,11 +62,17 @@ module OmniAuth
|
|
60
62
|
)
|
61
63
|
end
|
62
64
|
|
65
|
+
credentials do
|
66
|
+
# Tokens and expiration will be used from OAuth2 strategy credentials block
|
67
|
+
prune!({ 'scope' => token_info(access_token.token)['scope'] })
|
68
|
+
end
|
69
|
+
|
63
70
|
extra do
|
64
71
|
hash = {}
|
65
|
-
|
66
|
-
|
67
|
-
|
72
|
+
token = nil_or_empty?(access_token['id_token']) ? access_token.token : access_token['id_token']
|
73
|
+
hash[:id_token] = token
|
74
|
+
if !options[:skip_jwt] && !nil_or_empty?(token)
|
75
|
+
decoded = ::JWT.decode(token, nil, false).first
|
68
76
|
|
69
77
|
# We have to manually verify the claims because the third parameter to
|
70
78
|
# JWT.decode is false since no verification key is provided.
|
@@ -101,6 +109,10 @@ module OmniAuth
|
|
101
109
|
|
102
110
|
private
|
103
111
|
|
112
|
+
def nil_or_empty?(obj)
|
113
|
+
obj.is_a?(String) ? obj.empty? : obj.nil?
|
114
|
+
end
|
115
|
+
|
104
116
|
def callback_url
|
105
117
|
options[:redirect_uri] || (full_host + callback_path)
|
106
118
|
end
|
@@ -121,8 +133,9 @@ module OmniAuth
|
|
121
133
|
request.body.rewind # rewind request body for downstream middlewares
|
122
134
|
verifier = body && body['code']
|
123
135
|
access_token = body && body['access_token']
|
136
|
+
redirect_uri ||= body && body['redirect_uri']
|
124
137
|
if verifier
|
125
|
-
client_get_token(verifier, 'postmessage')
|
138
|
+
client_get_token(verifier, redirect_uri || 'postmessage')
|
126
139
|
elsif verify_token(access_token)
|
127
140
|
::OAuth2::AccessToken.from_hash(client, body.dup)
|
128
141
|
end
|
@@ -214,12 +227,21 @@ module OmniAuth
|
|
214
227
|
URI.encode_www_form(stripped_params)
|
215
228
|
end
|
216
229
|
|
230
|
+
def token_info(access_token)
|
231
|
+
return nil unless access_token
|
232
|
+
|
233
|
+
@token_info ||= Hash.new do |h, k|
|
234
|
+
h[k] = client.request(:get, 'https://www.googleapis.com/oauth2/v3/tokeninfo', params: { access_token: access_token }).parsed
|
235
|
+
end
|
236
|
+
|
237
|
+
@token_info[access_token]
|
238
|
+
end
|
239
|
+
|
217
240
|
def verify_token(access_token)
|
218
241
|
return false unless access_token
|
219
242
|
|
220
|
-
|
221
|
-
|
222
|
-
raw_response['aud'] == options.client_id || options.authorized_client_ids.include?(raw_response['aud'])
|
243
|
+
token_info = token_info(access_token)
|
244
|
+
token_info['aud'] == options.client_id || options.authorized_client_ids.include?(token_info['aud'])
|
223
245
|
end
|
224
246
|
|
225
247
|
def verify_hd(access_token)
|
@@ -21,9 +21,9 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.required_ruby_version = '>= 2.2'
|
22
22
|
|
23
23
|
gem.add_runtime_dependency 'jwt', '>= 2.0'
|
24
|
-
gem.add_runtime_dependency 'oauth2', '~>
|
24
|
+
gem.add_runtime_dependency 'oauth2', '~> 2.0.6'
|
25
25
|
gem.add_runtime_dependency 'omniauth', '~> 2.0'
|
26
|
-
gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.
|
26
|
+
gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.8.0'
|
27
27
|
|
28
28
|
gem.add_development_dependency 'rake', '~> 12.0'
|
29
29
|
gem.add_development_dependency 'rspec', '~> 3.6'
|
@@ -242,9 +242,18 @@ describe OmniAuth::Strategies::GoogleOauth2 do
|
|
242
242
|
context "authorize option #{k}" do
|
243
243
|
let(:request) { double('Request', params: { k.to_s => 'http://example.com' }, cookies: {}, env: {}) }
|
244
244
|
|
245
|
-
|
246
|
-
|
247
|
-
|
245
|
+
context 'when overridable_authorize_options is default' do
|
246
|
+
it "should set the #{k} authorize option dynamically in the request" do
|
247
|
+
@options = { k: '' }
|
248
|
+
expect(subject.authorize_params[k.to_s]).to eq('http://example.com')
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
context 'when overridable_authorize_options is empty' do
|
253
|
+
it "should not set the #{k} authorize option dynamically in the request" do
|
254
|
+
@options = { k: '', overridable_authorize_options: [] }
|
255
|
+
expect(subject.authorize_params[k.to_s]).not_to eq('http://example.com')
|
256
|
+
end
|
248
257
|
end
|
249
258
|
end
|
250
259
|
end
|
@@ -252,9 +261,18 @@ describe OmniAuth::Strategies::GoogleOauth2 do
|
|
252
261
|
describe 'custom authorize_options' do
|
253
262
|
let(:request) { double('Request', params: { 'foo' => 'something' }, cookies: {}, env: {}) }
|
254
263
|
|
255
|
-
|
256
|
-
|
257
|
-
|
264
|
+
context 'when overridable_authorize_options is default' do
|
265
|
+
it 'should not support request overrides from custom authorize_options' do
|
266
|
+
@options = { authorize_options: [:foo], foo: '' }
|
267
|
+
expect(subject.authorize_params['foo']).not_to eq('something')
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
context 'when overridable_authorize_options is customized' do
|
272
|
+
it 'should support request overrides from custom authorize_options' do
|
273
|
+
@options = { authorize_options: [:foo], overridable_authorize_options: [:foo], foo: '' }
|
274
|
+
expect(subject.authorize_params['foo']).to eq('something')
|
275
|
+
end
|
258
276
|
end
|
259
277
|
end
|
260
278
|
end
|
@@ -321,7 +339,7 @@ describe OmniAuth::Strategies::GoogleOauth2 do
|
|
321
339
|
end
|
322
340
|
end
|
323
341
|
end
|
324
|
-
let(:access_token) { OAuth2::AccessToken.from_hash(client, {}) }
|
342
|
+
let(:access_token) { OAuth2::AccessToken.from_hash(client, { 'access_token' => 'a' }) }
|
325
343
|
before { allow(subject).to receive(:access_token).and_return(access_token) }
|
326
344
|
|
327
345
|
context 'with verified email' do
|
@@ -347,6 +365,37 @@ describe OmniAuth::Strategies::GoogleOauth2 do
|
|
347
365
|
end
|
348
366
|
end
|
349
367
|
|
368
|
+
describe '#credentials' do
|
369
|
+
let(:client) { OAuth2::Client.new('abc', 'def') }
|
370
|
+
let(:access_token) { OAuth2::AccessToken.from_hash(client, access_token: 'valid_access_token', expires_at: 123_456_789, refresh_token: 'valid_refresh_token') }
|
371
|
+
before(:each) do
|
372
|
+
allow(subject).to receive(:access_token).and_return(access_token)
|
373
|
+
subject.options.client_options[:connection_build] = proc do |builder|
|
374
|
+
builder.request :url_encoded
|
375
|
+
builder.adapter :test do |stub|
|
376
|
+
stub.get('/oauth2/v3/tokeninfo?access_token=valid_access_token') do
|
377
|
+
[200, { 'Content-Type' => 'application/json; charset=UTF-8' }, JSON.dump(
|
378
|
+
aud: '000000000000.apps.googleusercontent.com',
|
379
|
+
sub: '123456789',
|
380
|
+
scope: 'profile email'
|
381
|
+
)]
|
382
|
+
end
|
383
|
+
end
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
it 'should return access token and (optionally) refresh token' do
|
388
|
+
expect(subject.credentials.to_h).to \
|
389
|
+
match(hash_including(
|
390
|
+
'token' => 'valid_access_token',
|
391
|
+
'refresh_token' => 'valid_refresh_token',
|
392
|
+
'scope' => 'profile email',
|
393
|
+
'expires_at' => 123_456_789,
|
394
|
+
'expires' => true
|
395
|
+
))
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
350
399
|
describe '#extra' do
|
351
400
|
let(:client) do
|
352
401
|
OAuth2::Client.new('abc', 'def') do |builder|
|
@@ -356,8 +405,6 @@ describe OmniAuth::Strategies::GoogleOauth2 do
|
|
356
405
|
end
|
357
406
|
end
|
358
407
|
end
|
359
|
-
let(:access_token) { OAuth2::AccessToken.from_hash(client, {}) }
|
360
|
-
|
361
408
|
before { allow(subject).to receive(:access_token).and_return(access_token) }
|
362
409
|
|
363
410
|
describe 'id_token' do
|
@@ -418,7 +465,10 @@ describe OmniAuth::Strategies::GoogleOauth2 do
|
|
418
465
|
end
|
419
466
|
end
|
420
467
|
|
421
|
-
context 'when the
|
468
|
+
context 'when the access token is empty or nil' do
|
469
|
+
let(:access_token) { OAuth2::AccessToken.new(client, nil, { 'refresh_token' => 'foo' }) }
|
470
|
+
before { allow(subject.extra).to receive(:access_token).and_return(access_token) }
|
471
|
+
|
422
472
|
it 'should not include id_token' do
|
423
473
|
expect(subject.extra).not_to have_key(:id_token)
|
424
474
|
end
|
@@ -430,6 +480,19 @@ describe OmniAuth::Strategies::GoogleOauth2 do
|
|
430
480
|
end
|
431
481
|
|
432
482
|
describe 'raw_info' do
|
483
|
+
let(:token_info) do
|
484
|
+
{
|
485
|
+
'abc' => 'xyz',
|
486
|
+
'exp' => Time.now.to_i + 3600,
|
487
|
+
'nbf' => Time.now.to_i - 60,
|
488
|
+
'iat' => Time.now.to_i,
|
489
|
+
'aud' => 'appid',
|
490
|
+
'iss' => 'accounts.google.com'
|
491
|
+
}
|
492
|
+
end
|
493
|
+
let(:id_token) { JWT.encode(token_info, 'secret') }
|
494
|
+
let(:access_token) { OAuth2::AccessToken.from_hash(client, 'id_token' => id_token) }
|
495
|
+
|
433
496
|
context 'when skip_info is true' do
|
434
497
|
before { subject.options[:skip_info] = true }
|
435
498
|
|
@@ -614,15 +677,22 @@ describe OmniAuth::Strategies::GoogleOauth2 do
|
|
614
677
|
end
|
615
678
|
|
616
679
|
it 'should read access_token from hash if this is not an AJAX request with a code parameter' do
|
680
|
+
client = OAuth2::Client.new('abc', 'def') do |builder|
|
681
|
+
builder.request :url_encoded
|
682
|
+
builder.adapter :test do |stub|
|
683
|
+
stub.get('/oauth2/v3/userinfo') { [200, { 'content-type' => 'application/json' }, '{"sub": "12345"}'] }
|
684
|
+
end
|
685
|
+
end
|
686
|
+
|
617
687
|
allow(request).to receive(:xhr?).and_return(false)
|
618
688
|
allow(request).to receive(:params).and_return('access_token' => 'valid_access_token')
|
619
689
|
expect(subject).to receive(:verify_token).with('valid_access_token').and_return true
|
620
|
-
expect(subject).to receive(:client).and_return(
|
690
|
+
expect(subject).to receive(:client).and_return(client)
|
621
691
|
|
622
692
|
token = subject.build_access_token
|
623
693
|
expect(token).to be_instance_of(::OAuth2::AccessToken)
|
624
694
|
expect(token.token).to eq('valid_access_token')
|
625
|
-
expect(token.client).to eq(
|
695
|
+
expect(token.client).to eq(client)
|
626
696
|
end
|
627
697
|
|
628
698
|
it 'reads the code from a json request body' do
|
@@ -641,20 +711,42 @@ describe OmniAuth::Strategies::GoogleOauth2 do
|
|
641
711
|
subject.build_access_token
|
642
712
|
end
|
643
713
|
|
714
|
+
it 'reads the redirect uri from a json request body' do
|
715
|
+
body = StringIO.new(%({"code":"json_access_token", "redirect_uri":"sample"}))
|
716
|
+
client = double(:client)
|
717
|
+
auth_code = double(:auth_code)
|
718
|
+
|
719
|
+
allow(request).to receive(:xhr?).and_return(false)
|
720
|
+
allow(request).to receive(:content_type).and_return('application/json')
|
721
|
+
allow(request).to receive(:body).and_return(body)
|
722
|
+
allow(client).to receive(:auth_code).and_return(auth_code)
|
723
|
+
expect(subject).to receive(:client).and_return(client)
|
724
|
+
|
725
|
+
expect(auth_code).to receive(:get_token).with('json_access_token', { redirect_uri: 'sample' }, {})
|
726
|
+
|
727
|
+
subject.build_access_token
|
728
|
+
end
|
729
|
+
|
644
730
|
it 'reads the access token from a json request body' do
|
645
731
|
body = StringIO.new(%({"access_token":"valid_access_token"}))
|
732
|
+
client = OAuth2::Client.new('abc', 'def') do |builder|
|
733
|
+
builder.request :url_encoded
|
734
|
+
builder.adapter :test do |stub|
|
735
|
+
stub.get('/oauth2/v3/userinfo') { [200, { 'content-type' => 'application/json' }, '{"sub": "12345"}'] }
|
736
|
+
end
|
737
|
+
end
|
646
738
|
|
647
739
|
allow(request).to receive(:xhr?).and_return(false)
|
648
740
|
allow(request).to receive(:content_type).and_return('application/json')
|
649
741
|
allow(request).to receive(:body).and_return(body)
|
650
|
-
expect(subject).to receive(:client).and_return(
|
742
|
+
expect(subject).to receive(:client).and_return(client)
|
651
743
|
|
652
744
|
expect(subject).to receive(:verify_token).with('valid_access_token').and_return true
|
653
745
|
|
654
746
|
token = subject.build_access_token
|
655
747
|
expect(token).to be_instance_of(::OAuth2::AccessToken)
|
656
748
|
expect(token.token).to eq('valid_access_token')
|
657
|
-
expect(token.client).to eq(
|
749
|
+
expect(token.client).to eq(client)
|
658
750
|
end
|
659
751
|
|
660
752
|
it 'should use callback_url without query_string if this is not an AJAX request' do
|
@@ -730,7 +822,7 @@ describe OmniAuth::Strategies::GoogleOauth2 do
|
|
730
822
|
end
|
731
823
|
end
|
732
824
|
end
|
733
|
-
let(:access_token) { OAuth2::AccessToken.from_hash(client, {}) }
|
825
|
+
let(:access_token) { OAuth2::AccessToken.from_hash(client, { 'access_token' => 'foo' }) }
|
734
826
|
|
735
827
|
context 'when domain is nil' do
|
736
828
|
let(:client) do
|
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: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Ellithorpe
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-09-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jwt
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: 2.0.6
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: 2.0.6
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: omniauth
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,14 +59,14 @@ dependencies:
|
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: 1.
|
62
|
+
version: 1.8.0
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 1.
|
69
|
+
version: 1.8.0
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rake
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -117,6 +117,7 @@ executables: []
|
|
117
117
|
extensions: []
|
118
118
|
extra_rdoc_files: []
|
119
119
|
files:
|
120
|
+
- ".github/workflows/ci.yml"
|
120
121
|
- ".gitignore"
|
121
122
|
- ".rubocop.yml"
|
122
123
|
- ".travis.yml"
|
@@ -154,8 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
155
|
- !ruby/object:Gem::Version
|
155
156
|
version: '0'
|
156
157
|
requirements: []
|
157
|
-
|
158
|
-
rubygems_version: 2.7.9
|
158
|
+
rubygems_version: 3.0.9
|
159
159
|
signing_key:
|
160
160
|
specification_version: 4
|
161
161
|
summary: A Google OAuth2 strategy for OmniAuth 1.x
|