omniauth-google-oauth2 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adbd87cbf3dc07abbc3f14d2923a655b78cae9701432c0f0866e959eeb946606
4
- data.tar.gz: f4b975b570dd5b96032402766be88e8537f419ea361564275b2e84b97bd2cdb9
3
+ metadata.gz: 45ce2b17155396ac41a875e3bcadfd9827cf45b30d2c64309992b84d3ef0088d
4
+ data.tar.gz: d9f9e89a3526a81b19a66a222b3534848c66914a34960500a6ed57fe23e40fdd
5
5
  SHA512:
6
- metadata.gz: 0445f4e07feba58d9b850dcf6d0a45e256a9e6557de6f5a248b0ac8e42004446eb9bc31cfa3dd3f61cb0baab276b3d85b17f302863f81f0560c4532f58a05115
7
- data.tar.gz: 4a7c65a13c017c7da47d8a82e86615e51af46c32d20dcf25d4fcc6451b81299a63c291b78b3b956ddc4c015d97e2d2c855efa6647ad29f7cda25171746231e4a
6
+ metadata.gz: 543ac7161867df4ec9826c29ccebe89ae70348b3038095b747b2160f2988c2cdcfccb418d4afaaff6b564e8df4aafa5dd704f8632cbd755ef5d222b7a6e63697
7
+ data.tar.gz: 2585a702d4595b4986c6406fc8121e4f61ff4fc4558372fc689e28cc87ce21ba8a387b8999a2cc1c53bcfa96df6e68457777f493675c71a511f9e0d5adae12e6
@@ -7,7 +7,7 @@ jobs:
7
7
  runs-on: ubuntu-latest
8
8
  strategy:
9
9
  matrix:
10
- ruby-version: ['2.3', '2.4', '2.5', '2.6', '2.7', '3.0', '3.1', '3.2', truffleruby-head]
10
+ ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2', truffleruby-head]
11
11
 
12
12
  steps:
13
13
  - uses: actions/checkout@v2
data/.rubocop.yml CHANGED
@@ -6,7 +6,7 @@ Metrics/BlockLength:
6
6
  ExcludedMethods: ['describe', 'context', 'shared_examples']
7
7
  Metrics/CyclomaticComplexity:
8
8
  Enabled: false
9
- Metrics/LineLength:
9
+ Layout/LineLength:
10
10
  Enabled: false
11
11
  Metrics/MethodLength:
12
12
  Enabled: false
@@ -18,3 +18,15 @@ Style/MutableConstant:
18
18
  Enabled: false
19
19
  Gemspec/RequiredRubyVersion:
20
20
  Enabled: false
21
+ Lint/RaiseException:
22
+ Enabled: false
23
+ Lint/StructNewOverride:
24
+ Enabled: false
25
+ Style/HashEachMethods:
26
+ Enabled: false
27
+ Style/HashTransformKeys:
28
+ Enabled: false
29
+ Style/HashTransformValues:
30
+ Enabled: false
31
+ AllCops:
32
+ NewCops: enable
data/CHANGELOG.md CHANGED
@@ -1,6 +1,37 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## 1.2.0 - 2024-09-15
5
+
6
+ ### Added
7
+ - jwt 2.9.0 support for their updated claims code.
8
+
9
+ ### Deprecated
10
+ - Nothing.
11
+
12
+ ### Removed
13
+ - Ruby 2.3 and 2.4 support.
14
+ - Support for jwt < 2.9.0.
15
+
16
+ ### Fixed
17
+ - Fixed image sizing code.
18
+ - Rubocop configuration updates.
19
+
20
+ ## 1.1.3 - 2024-08-29
21
+
22
+ ### Added
23
+ - Updated to use POST instead of GET for tokeninfo endpoint.
24
+
25
+ ### Deprecated
26
+ - Nothing.
27
+
28
+ ### Removed
29
+ - Nothing.
30
+
31
+ ### Fixed
32
+ - Documentation typos.
33
+ - Rubocop configuration updates.
34
+
4
35
  ## 1.1.2 - 2024-03-28
5
36
 
6
37
  ### Added
data/README.md CHANGED
@@ -40,7 +40,7 @@ You can now access the OmniAuth Google OAuth2 URL: `/auth/google_oauth2`
40
40
 
41
41
  For more examples please check out `examples/omni_auth.rb`
42
42
 
43
- [Using Devise? Skip the above and jump down to the Devise section!](#devise) After setting up the provider via Devise, you can reference the confdiurations below.
43
+ [Using Devise? Skip the above and jump down to the Devise section!](#devise) After setting up the provider via Devise, you can reference the configurations below.
44
44
 
45
45
  NOTE: While developing your application, if you change the scope in the initializer you will need to restart your app server. Remember that either the 'email' or 'profile' scope is required!
46
46
 
@@ -64,6 +64,7 @@ You can configure several options, which you pass in to the `provider` method vi
64
64
  * `image_aspect_ratio`: The shape of the user's profile picture. Possible values are:
65
65
  * `original`: Picture maintains its original aspect ratio.
66
66
  * `square`: Picture presents equal width and height.
67
+ * `smart`: Picture presents equal width and height with smart cropping.
67
68
 
68
69
  Defaults to `original`.
69
70
 
@@ -205,6 +206,8 @@ end
205
206
  and bind to or create the user
206
207
 
207
208
  ```ruby
209
+ # app/models/user.rb
210
+
208
211
  def self.from_omniauth(access_token)
209
212
  data = access_token.info
210
213
  user = User.where(email: data['email']).first
@@ -233,7 +236,7 @@ For your views you can login using:
233
236
  <%= link_to "Sign in with Google", user_omniauth_authorize_path(:google_oauth2) %>
234
237
  ```
235
238
 
236
- An overview is available at https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
239
+ An overview is available at https://github.com/heartcombo/devise/wiki/OmniAuth:-Overview
237
240
 
238
241
  ### One-time Code Flow (Hybrid Authentication)
239
242
 
data/examples/Gemfile CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- gem 'omniauth-google-oauth2', '~> 1.1.2'
5
+ gem 'omniauth-google-oauth2', '~> 1.2.0'
6
6
  gem 'rubocop'
7
7
  gem 'sinatra', '~> 1.4'
8
8
  gem 'webrick'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAuth
4
4
  module GoogleOauth2
5
- VERSION = '1.1.2'
5
+ VERSION = '1.2.0'
6
6
  end
7
7
  end
@@ -76,17 +76,17 @@ module OmniAuth
76
76
 
77
77
  # We have to manually verify the claims because the third parameter to
78
78
  # JWT.decode is false since no verification key is provided.
79
- ::JWT::Verify.verify_claims(decoded,
80
- verify_iss: true,
81
- iss: ALLOWED_ISSUERS,
82
- verify_aud: true,
83
- aud: options.client_id,
84
- verify_sub: false,
85
- verify_expiration: true,
86
- verify_not_before: true,
87
- verify_iat: false,
88
- verify_jti: false,
89
- leeway: options[:jwt_leeway])
79
+ ::JWT::Claims.verify!(decoded,
80
+ verify_iss: true,
81
+ iss: ALLOWED_ISSUERS,
82
+ verify_aud: true,
83
+ aud: options.client_id,
84
+ verify_sub: false,
85
+ verify_expiration: true,
86
+ verify_not_before: true,
87
+ verify_iat: false,
88
+ verify_jti: false,
89
+ leeway: options[:jwt_leeway])
90
90
 
91
91
  hash[:id_info] = decoded
92
92
  end
@@ -178,17 +178,16 @@ module OmniAuth
178
178
  def image_url
179
179
  return nil unless raw_info['picture']
180
180
 
181
- u = URI.parse(raw_info['picture'].gsub('https:https', 'https'))
181
+ u = URI.parse(raw_info['picture'])
182
182
 
183
- path_index = u.path.to_s.index('/photo.jpg')
183
+ md = u.path.to_s.match(/(.*)(=((w[0-9]*|h[0-9]*|s[0-9]*|c|p)-?)*)$/)
184
184
 
185
- if path_index && image_size_opts_passed?
186
- u.path.insert(path_index, image_params)
187
- u.path = u.path.gsub('//', '/')
185
+ # Check for sizing, remove if present.
186
+ u.path = md[1] if md && !md[1].nil? && !md[2].nil?
188
187
 
189
- # Check if the image is already sized!
190
- split_path = u.path.split('/')
191
- u.path = u.path.sub("/#{split_path[-3]}", '') if split_path[-3] =~ IMAGE_SIZE_REGEXP
188
+ if image_size_opts_passed?
189
+ u.path += image_params
190
+ u.path = u.path.gsub('//', '/')
192
191
  end
193
192
 
194
193
  u.query = strip_unnecessary_query_parameters(u.query)
@@ -202,15 +201,17 @@ module OmniAuth
202
201
 
203
202
  def image_params
204
203
  image_params = []
205
- if options[:image_size].is_a?(Integer)
204
+ case options[:image_size]
205
+ when Integer
206
206
  image_params << "s#{options[:image_size]}"
207
- elsif options[:image_size].is_a?(Hash)
207
+ when Hash
208
208
  image_params << "w#{options[:image_size][:width]}" if options[:image_size][:width]
209
209
  image_params << "h#{options[:image_size][:height]}" if options[:image_size][:height]
210
210
  end
211
211
  image_params << 'c' if options[:image_aspect_ratio] == 'square'
212
+ image_params << 'p' if options[:image_aspect_ratio] == 'smart'
212
213
 
213
- '/' + image_params.join('-')
214
+ "=#{image_params.join('-')}"
214
215
  end
215
216
 
216
217
  def strip_unnecessary_query_parameters(query_parameters)
@@ -231,7 +232,7 @@ module OmniAuth
231
232
  return nil unless access_token
232
233
 
233
234
  @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
+ h[k] = client.request(:post, 'https://www.googleapis.com/oauth2/v3/tokeninfo', body: { access_token: access_token }).parsed
235
236
  end
236
237
 
237
238
  @token_info[access_token]
@@ -18,9 +18,9 @@ Gem::Specification.new do |gem|
18
18
  gem.files = `git ls-files`.split("\n")
19
19
  gem.require_paths = ['lib']
20
20
 
21
- gem.required_ruby_version = '>= 2.2'
21
+ gem.required_ruby_version = '>= 2.5'
22
22
 
23
- gem.add_runtime_dependency 'jwt', '>= 2.0'
23
+ gem.add_runtime_dependency 'jwt', '>= 2.9'
24
24
  gem.add_runtime_dependency 'oauth2', '~> 2.0'
25
25
  gem.add_runtime_dependency 'omniauth', '~> 2.0'
26
26
  gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.8'
@@ -324,20 +324,20 @@ describe OmniAuth::Strategies::GoogleOauth2 do
324
324
  it 'has the correct default callback path' do
325
325
  allow(subject).to receive(:full_host) { base_url }
326
326
  allow(subject).to receive(:script_name) { '' }
327
- expect(subject.send(:callback_url)).to eq(base_url + '/auth/google_oauth2/callback')
327
+ expect(subject.send(:callback_url)).to eq("#{base_url}/auth/google_oauth2/callback")
328
328
  end
329
329
 
330
330
  it 'should set the callback path with script_name if present' do
331
331
  allow(subject).to receive(:full_host) { base_url }
332
332
  allow(subject).to receive(:script_name) { '/v1' }
333
- expect(subject.send(:callback_url)).to eq(base_url + '/v1/auth/google_oauth2/callback')
333
+ expect(subject.send(:callback_url)).to eq("#{base_url}/v1/auth/google_oauth2/callback")
334
334
  end
335
335
 
336
336
  it 'should set the callback_path parameter if present' do
337
337
  @options = { callback_path: '/auth/foo/callback' }
338
338
  allow(subject).to receive(:full_host) { base_url }
339
339
  allow(subject).to receive(:script_name) { '' }
340
- expect(subject.send(:callback_url)).to eq(base_url + '/auth/foo/callback')
340
+ expect(subject.send(:callback_url)).to eq("#{base_url}/auth/foo/callback")
341
341
  end
342
342
  end
343
343
 
@@ -384,7 +384,7 @@ describe OmniAuth::Strategies::GoogleOauth2 do
384
384
  subject.options.client_options[:connection_build] = proc do |builder|
385
385
  builder.request :url_encoded
386
386
  builder.adapter :test do |stub|
387
- stub.get('/oauth2/v3/tokeninfo?access_token=valid_access_token') do
387
+ stub.post('/oauth2/v3/tokeninfo', 'access_token=valid_access_token') do
388
388
  [200, { 'Content-Type' => 'application/json; charset=UTF-8' }, JSON.dump(
389
389
  aud: '000000000000.apps.googleusercontent.com',
390
390
  sub: '123456789',
@@ -544,103 +544,146 @@ describe OmniAuth::Strategies::GoogleOauth2 do
544
544
  describe 'when a picture is returned from google' do
545
545
  it 'should return the image with size specified in the `image_size` option' do
546
546
  @options = { image_size: 50 }
547
- allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/url/photo.jpg' } }
548
- expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/url/s50/photo.jpg')
547
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0' } }
548
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=s50')
549
549
  end
550
550
 
551
551
  it 'should return the image with size specified in the `image_size` option when sizing is in the picture' do
552
552
  @options = { image_size: 50 }
553
- allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh4.googleusercontent.com/url/s96-c/photo.jpg' } }
554
- expect(subject.info[:image]).to eq('https://lh4.googleusercontent.com/url/s50/photo.jpg')
553
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=s96' } }
554
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=s50')
555
555
  end
556
556
 
557
- it 'should handle a picture with too many slashes correctly' do
557
+ it 'should return the image with size specified in the `image_size` option when sizing is in the picture and cropped' do
558
558
  @options = { image_size: 50 }
559
- allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/url//photo.jpg' } }
560
- expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/url/s50/photo.jpg')
559
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=s96-c' } }
560
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=s50')
561
561
  end
562
562
 
563
- it 'should handle a picture with a size query parameter correctly' do
563
+ it 'should handle a picture with too many slashes' do
564
564
  @options = { image_size: 50 }
565
- allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/url/photo.jpg?sz=50' } }
566
- expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/url/s50/photo.jpg')
565
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a//ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0' } }
566
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=s50')
567
+ end
568
+
569
+ it 'should handle a picture with a size query parameter' do
570
+ @options = { image_size: 50 }
571
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0?sz=96' } }
572
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=s50')
573
+ end
574
+
575
+ it 'should handle a picture with a size query parameter and sizing is in the picture' do
576
+ @options = { image_size: 50 }
577
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=s96-c?sz=96' } }
578
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=s50')
567
579
  end
568
580
 
569
581
  it 'should handle a picture with a size query parameter and other valid query parameters correctly' do
570
582
  @options = { image_size: 50 }
571
- allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/url/photo.jpg?sz=50&hello=true&life=42' } }
572
- expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/url/s50/photo.jpg?hello=true&life=42')
583
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0?sz=50&hello=true&life=42' } }
584
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=s50?hello=true&life=42')
585
+ end
586
+
587
+ it 'should handle a picture with a size query parameter, other valid query parameters and sizing is in the picture correctly' do
588
+ @options = { image_size: 50 }
589
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=s96-c?sz=50&hello=true&life=42' } }
590
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=s50?hello=true&life=42')
573
591
  end
574
592
 
575
593
  it 'should handle a picture with other valid query parameters correctly' do
576
594
  @options = { image_size: 50 }
577
- allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/url/photo.jpg?hello=true&life=42' } }
578
- expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/url/s50/photo.jpg?hello=true&life=42')
595
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0?hello=true&life=42' } }
596
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=s50?hello=true&life=42')
579
597
  end
580
598
 
581
599
  it 'should return the image with width and height specified in the `image_size` option' do
582
600
  @options = { image_size: { width: 50, height: 40 } }
583
- allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/url/photo.jpg' } }
584
- expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/url/w50-h40/photo.jpg')
601
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0' } }
602
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=w50-h40')
585
603
  end
586
604
 
587
605
  it 'should return the image with width and height specified in the `image_size` option when sizing is in the picture' do
588
606
  @options = { image_size: { width: 50, height: 40 } }
589
- allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/url/w100-h80-c/photo.jpg' } }
590
- expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/url/w50-h40/photo.jpg')
607
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=w100-h80-c' } }
608
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=w50-h40')
591
609
  end
592
610
 
593
- it 'should return square image when `image_aspect_ratio` is specified' do
611
+ it 'should return square image when square `image_aspect_ratio` is specified' do
594
612
  @options = { image_aspect_ratio: 'square' }
595
- allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/url/photo.jpg' } }
596
- expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/url/c/photo.jpg')
613
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0' } }
614
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=c')
597
615
  end
598
616
 
599
- it 'should return square image when `image_aspect_ratio` is specified and sizing is in the picture' do
617
+ it 'should return square image when square `image_aspect_ratio` is specified and sizing is in the picture' do
600
618
  @options = { image_aspect_ratio: 'square' }
601
- allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/url/c/photo.jpg' } }
602
- expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/url/c/photo.jpg')
619
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=s50-c' } }
620
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=c')
621
+ end
622
+
623
+ it 'should return smart image when smart `image_aspect_ratio` is specified' do
624
+ @options = { image_aspect_ratio: 'smart' }
625
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0' } }
626
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=p')
603
627
  end
604
628
 
605
- it 'should return square sized image when `image_aspect_ratio` and `image_size` is set' do
629
+ it 'should return smart image when smart `image_aspect_ratio` is specified and sizing is in the picture' do
630
+ @options = { image_aspect_ratio: 'smart' }
631
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=s50-c' } }
632
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=p')
633
+ end
634
+
635
+ it 'should return square sized image when square `image_aspect_ratio` and `image_size` is set' do
606
636
  @options = { image_aspect_ratio: 'square', image_size: 50 }
607
- allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/url/photo.jpg' } }
608
- expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/url/s50-c/photo.jpg')
637
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0' } }
638
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=s50-c')
609
639
  end
610
640
 
611
- it 'should return square sized image when `image_aspect_ratio` and `image_size` is set and sizing is in the picture' do
641
+ it 'should return square sized image when square `image_aspect_ratio` and `image_size` is set and sizing is in the picture' do
612
642
  @options = { image_aspect_ratio: 'square', image_size: 50 }
613
- allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/url/s90/photo.jpg' } }
614
- expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/url/s50-c/photo.jpg')
643
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=s90' } }
644
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=s50-c')
645
+ end
646
+
647
+ it 'should return smart sized image when smart `image_aspect_ratio` and `image_size` is set' do
648
+ @options = { image_aspect_ratio: 'smart', image_size: 50 }
649
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0' } }
650
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=s50-p')
651
+ end
652
+
653
+ it 'should return smart sized image when smart `image_aspect_ratio` and `image_size` is set and sizing is in the picture' do
654
+ @options = { image_aspect_ratio: 'smart', image_size: 50 }
655
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=s90' } }
656
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=s50-p')
615
657
  end
616
658
 
617
- it 'should return square sized image when `image_aspect_ratio` and `image_size` has height and width' do
659
+ it 'should return square sized image when square `image_aspect_ratio` and `image_size` has height and width' do
618
660
  @options = { image_aspect_ratio: 'square', image_size: { width: 50, height: 40 } }
619
- allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/url/photo.jpg' } }
620
- expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/url/w50-h40-c/photo.jpg')
661
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0' } }
662
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=w50-h40-c')
621
663
  end
622
664
 
623
- it 'should return square sized image when `image_aspect_ratio` and `image_size` has height and width and sizing is in the picture' do
665
+ it 'should return square sized image when square `image_aspect_ratio` and `image_size` has height and width and sizing is in the picture' do
624
666
  @options = { image_aspect_ratio: 'square', image_size: { width: 50, height: 40 } }
625
- allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/url/w100-h80/photo.jpg' } }
626
- expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/url/w50-h40-c/photo.jpg')
667
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=w100-h80-c' } }
668
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=w50-h40-c')
627
669
  end
628
670
 
629
- it 'should return original image if image url does not end in `photo.jpg`' do
630
- @options = { image_size: 50 }
631
- allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/url/photograph.jpg' } }
632
- expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/url/photograph.jpg')
671
+ it 'should return smart sized image when smart `image_aspect_ratio` and `image_size` has height and width' do
672
+ @options = { image_aspect_ratio: 'smart', image_size: { width: 50, height: 40 } }
673
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0' } }
674
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=w50-h40-p')
633
675
  end
634
- end
635
676
 
636
- it 'should return original image if no options are provided' do
637
- allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/url/photo.jpg' } }
638
- expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/url/photo.jpg')
677
+ it 'should return smart sized image when smart `image_aspect_ratio` and `image_size` has height and width and sizing is in the picture' do
678
+ @options = { image_aspect_ratio: 'smart', image_size: { width: 50, height: 40 } }
679
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=w100-h80-c' } }
680
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0=w50-h40-p')
681
+ end
639
682
  end
640
683
 
641
- it 'should return correct image if google image url has double https' do
642
- allow(subject).to receive(:raw_info) { { 'picture' => 'https:https://lh3.googleusercontent.com/url/photo.jpg' } }
643
- expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/url/photo.jpg')
684
+ it 'should return original image if no options are provided' do
685
+ allow(subject).to receive(:raw_info) { { 'picture' => 'https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0' } }
686
+ expect(subject.info[:image]).to eq('https://lh3.googleusercontent.com/a/ACg8ocKN8F32STvmW-LG0Rl_9re5-Pv2cCn0ayodas6BQFPGEArMOtn0')
644
687
  end
645
688
  end
646
689
 
@@ -781,7 +824,7 @@ describe OmniAuth::Strategies::GoogleOauth2 do
781
824
  subject.options.client_options[:connection_build] = proc do |builder|
782
825
  builder.request :url_encoded
783
826
  builder.adapter :test do |stub|
784
- stub.get('/oauth2/v3/tokeninfo?access_token=valid_access_token') do
827
+ stub.post('/oauth2/v3/tokeninfo', 'access_token=valid_access_token') do
785
828
  [200, { 'Content-Type' => 'application/json; charset=UTF-8' }, JSON.dump(
786
829
  aud: '000000000000.apps.googleusercontent.com',
787
830
  sub: '123456789',
@@ -792,7 +835,7 @@ describe OmniAuth::Strategies::GoogleOauth2 do
792
835
  expires_in: 436
793
836
  )]
794
837
  end
795
- stub.get('/oauth2/v3/tokeninfo?access_token=invalid_access_token') do
838
+ stub.post('/oauth2/v3/tokeninfo', 'access_token=invalid_access_token') do
796
839
  [400, { 'Content-Type' => 'application/json; charset=UTF-8' }, JSON.dump(error_description: 'Invalid Value')]
797
840
  end
798
841
  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: 1.1.2
4
+ version: 1.2.0
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: 2024-03-29 00:00:00.000000000 Z
12
+ date: 2024-09-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jwt
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '2.0'
20
+ version: '2.9'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '2.0'
27
+ version: '2.9'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: oauth2
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -147,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
147
  requirements:
148
148
  - - ">="
149
149
  - !ruby/object:Gem::Version
150
- version: '2.2'
150
+ version: '2.5'
151
151
  required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  requirements:
153
153
  - - ">="