omniauth-google-oauth2 0.2.10 → 0.3.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
  SHA1:
3
- metadata.gz: 3ede9c8b2ed21745e5e2455baa4bffa9b080a5af
4
- data.tar.gz: 5a7c985d8e1940b7cf07ab4dcf8025491ec69e38
3
+ metadata.gz: c7d06ea95829577b987b0c3f38361bbf0d53ac9c
4
+ data.tar.gz: ddade281a6be78eb43318effaee6fe1eb0c748ca
5
5
  SHA512:
6
- metadata.gz: 4d52a2e108594667e40b2334d7d5fdf3624ca2390cb7099b663747586765dc0ee0ba7527578fd4db43e2b16d82a703701be07346eef148c32e2e2e7fdfa45bb8
7
- data.tar.gz: 06ec6644022308248167bceea0ff590b6964b24dd548497610ac28a6bd5cad64b38948caa8ca21ca4cf5a94566bfb6b9f595c5311375461ecd8d005c4eb33c7f
6
+ metadata.gz: 8515c0e13e3eeb43fb96b53ffd989126044dddf06c3f6e510b903eee69edc49cde9915e82d547fe77004124c5dbd6eec1166a3cbe78b1e9795a56228df540c9e
7
+ data.tar.gz: 41c8b9757efade6cf94c50f29d564c94286f2debb2bb8ed9983923d964b3a6076debb238a02cb92488cd590d6937a8c8b583305076d88be59aa7146c86f8132f
data/CHANGELOG.md CHANGED
@@ -1,6 +1,20 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## 0.3.0 - 2016-01-09
5
+
6
+ ### Added
7
+ - Updated verify_token to use the v3 tokeninfo endpoint.
8
+
9
+ ### Deprecated
10
+ - Nothing.
11
+
12
+ ### Removed
13
+ - Nothing.
14
+
15
+ ### Fixed
16
+ - Compatibility with omniauth-oauth2 1.4.0
17
+
4
18
  ## 0.2.10 - 2015-11-05
5
19
 
6
20
  ### Added
data/README.md CHANGED
@@ -67,7 +67,7 @@ You can configure several options, which you pass in to the `provider` method vi
67
67
 
68
68
  * `name`: The name of the strategy. The default name is `google_oauth2` but it can be changed to any value, for example `google`. The OmniAuth URL will thus change to `/auth/google` and the `provider` key in the auth hash will then return `google`.
69
69
 
70
- * `access_type`: Defaults to `offline`, so a refresh token is sent to be used when the user is not present at the browser. Can be set to `online`. Note that if you need a refresh token, google requires you to also to specify the option `prompt: 'consent'`, which is not a default.
70
+ * `access_type`: Defaults to `offline`, so a refresh token is sent to be used when the user is not present at the browser. Can be set to `online`. More about [offline access](https://developers.google.com/identity/protocols/OAuth2WebServer#offline)
71
71
 
72
72
  * `hd`: (Optional) Limit sign-in to a particular Google Apps hosted domain. More information at: https://developers.google.com/accounts/docs/OpenIDConnect#hd-param
73
73
 
@@ -245,8 +245,8 @@ window.gpAsyncInit = function() {
245
245
  }, function(response) {
246
246
  if (response && !response.error) {
247
247
  // google authentication succeed, now post data to server and handle data securely
248
- jQuery.ajax({type: 'POST', url: "/auth/google_oauth2/callback", dataType: 'json', data: response,
249
- success: function(json) {
248
+ jQuery.ajax({type: 'POST', url: "/auth/google_oauth2/callback", data: response,
249
+ success: function(data) {
250
250
  // response from server
251
251
  }
252
252
  });
@@ -11,11 +11,9 @@ Rails.application.config.middleware.use OmniAuth::Builder do
11
11
  }
12
12
 
13
13
  # Manual setup for offline access with a refresh token.
14
- # The prompt must be set to 'consent'
15
14
  #
16
15
  # provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'], {
17
16
  # :access_type => 'offline',
18
- # :prompt => 'consent'
19
17
  # }
20
18
 
21
19
  # Custom scope supporting youtube. If you are customizing scopes, remember
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module GoogleOauth2
3
- VERSION = "0.2.10"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -100,14 +100,18 @@ module OmniAuth
100
100
  elsif verify_token(request.params['access_token'])
101
101
  ::OAuth2::AccessToken.from_hash(client, request.params.dup)
102
102
  else
103
- orig_build_access_token
103
+ verifier = request.params["code"]
104
+ client.auth_code.get_token(verifier, get_token_options(callback_url), deep_symbolize(options.auth_token_params))
104
105
  end
105
106
  end
106
- alias_method :orig_build_access_token, :build_access_token
107
107
  alias_method :build_access_token, :custom_build_access_token
108
108
 
109
109
  private
110
110
 
111
+ def callback_url
112
+ options[:redirect_uri] || (full_host + script_name + callback_path)
113
+ end
114
+
111
115
  def get_token_options(redirect_uri)
112
116
  { :redirect_uri => redirect_uri }.merge(token_params.to_hash(:symbolize_keys => true))
113
117
  end
@@ -171,9 +175,9 @@ module OmniAuth
171
175
 
172
176
  def verify_token(access_token)
173
177
  return false unless access_token
174
- raw_response = client.request(:get, 'https://www.googleapis.com/oauth2/v2/tokeninfo',
178
+ raw_response = client.request(:get, 'https://www.googleapis.com/oauth2/v3/tokeninfo',
175
179
  params: { access_token: access_token }).parsed
176
- raw_response['issued_to'] == options.client_id
180
+ raw_response['aud'] == options.client_id
177
181
  end
178
182
  end
179
183
  end
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
 
17
17
  gem.add_runtime_dependency 'omniauth', '>= 1.1.1'
18
- gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.3.1'
18
+ gem.add_runtime_dependency 'omniauth-oauth2', '>= 1.3.1'
19
19
  gem.add_runtime_dependency 'jwt', '~> 1.0'
20
20
  gem.add_runtime_dependency 'multi_json', '~> 1.3'
21
21
  gem.add_runtime_dependency 'addressable', '~> 2.3'
@@ -255,9 +255,15 @@ describe OmniAuth::Strategies::GoogleOauth2 do
255
255
  end
256
256
 
257
257
  describe '#callback_path' do
258
- it 'has the correct callback path' do
258
+ it 'has the correct default callback path' do
259
259
  expect(subject.callback_path).to eq('/auth/google_oauth2/callback')
260
260
  end
261
+
262
+ it 'should set the callback_path parameter if present' do
263
+ @options = {:callback_path => '/auth/foo/callback'}
264
+ expect(subject.callback_path).to eq('/auth/foo/callback')
265
+ end
266
+
261
267
  end
262
268
 
263
269
  describe '#extra' do
@@ -531,10 +537,17 @@ describe OmniAuth::Strategies::GoogleOauth2 do
531
537
  expect(token.client).to eq(:client)
532
538
  end
533
539
 
534
- it 'should call super if this is not an AJAX request' do
540
+ it 'should use callback_url without query_string if this is not an AJAX request' do
535
541
  allow(request).to receive(:xhr?).and_return(false)
536
542
  allow(request).to receive(:params).and_return('code' => 'valid_code')
537
- expect(subject).to receive(:orig_build_access_token)
543
+
544
+ client = double(:client)
545
+ auth_code = double(:auth_code)
546
+ allow(client).to receive(:auth_code).and_return(auth_code)
547
+ allow(subject).to receive(:callback_url).and_return('redirect_uri_without_query_string')
548
+
549
+ expect(subject).to receive(:client).and_return(client)
550
+ expect(auth_code).to receive(:get_token).with('valid_code', { :redirect_uri => 'redirect_uri_without_query_string'}, {})
538
551
  subject.build_access_token
539
552
  end
540
553
  end
@@ -544,19 +557,18 @@ describe OmniAuth::Strategies::GoogleOauth2 do
544
557
  subject.options.client_options[:connection_build] = proc do |builder|
545
558
  builder.request :url_encoded
546
559
  builder.adapter :test do |stub|
547
- stub.get('/oauth2/v2/tokeninfo?access_token=valid_access_token') do |env|
560
+ stub.get('/oauth2/v3/tokeninfo?access_token=valid_access_token') do |env|
548
561
  [200, {'Content-Type' => 'application/json; charset=UTF-8'}, MultiJson.encode(
549
- :issued_to => '000000000000.apps.googleusercontent.com',
550
- :audience => '000000000000.apps.googleusercontent.com',
551
- :user_id => '000000000000000000000',
552
- :scope => 'profile email',
553
- :expires_in => 3514,
554
- :email => 'me@example.com',
555
- :verified_email => true,
556
- :access_type => 'online'
562
+ :aud => "000000000000.apps.googleusercontent.com",
563
+ :sub => "123456789",
564
+ :email_verified => "true",
565
+ :email => "example@example.com",
566
+ :access_type => "offline",
567
+ :scope => "profile email",
568
+ :expires_in => 436
557
569
  )]
558
570
  end
559
- stub.get('/oauth2/v2/tokeninfo?access_token=invalid_access_token') do |env|
571
+ stub.get('/oauth2/v3/tokeninfo?access_token=invalid_access_token') do |env|
560
572
  [400, {'Content-Type' => 'application/json; charset=UTF-8'}, MultiJson.encode(:error_description => 'Invalid Value')]
561
573
  end
562
574
  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.2.10
4
+ version: 0.3.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: 2015-11-05 00:00:00.000000000 Z
12
+ date: 2016-01-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: omniauth
@@ -29,14 +29,14 @@ dependencies:
29
29
  name: omniauth-oauth2
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: 1.3.1
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
41
  version: 1.3.1
42
42
  - !ruby/object:Gem::Dependency
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  version: '0'
153
153
  requirements: []
154
154
  rubyforge_project:
155
- rubygems_version: 2.4.3
155
+ rubygems_version: 2.5.1
156
156
  signing_key:
157
157
  specification_version: 4
158
158
  summary: A Google OAuth2 strategy for OmniAuth 1.x