oauth2 2.0.3 → 2.0.6

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: 834cadcf40991f2fd88a74f9ee614992d17c087d5862a4f7243cb83874f87683
4
- data.tar.gz: 9a54a67d2def4e8232ff7b764ce70d87c4d9fb7125b72e234d07b84b507565b2
3
+ metadata.gz: 6ca4e3435d4b69bcdf5607cf41d9b5f67b3671160d860cda0e8a66fdc6ca9ea7
4
+ data.tar.gz: 74170cea4731366ce12134db250ca23b937791a349b3cb62c6833a729d8964fa
5
5
  SHA512:
6
- metadata.gz: 190394d6e1d046de982b9ed978c54b810a15cbfbe41507c63f103a19be06b04d4a7f2a8cad4f3fc30c9cf4eed6314e353668b7e49d8e41826e1c460f944060ed
7
- data.tar.gz: 10bd8f3f468165150ce7d79c31d0a4c7be72322660ae7579bf579bf68054106f21d16b408c56eedcc3a2359f14c84c770fa89dec93d0811c2ed328aa7b365f00
6
+ metadata.gz: '02886a1ab24fe6cc0f2a0624646fd07b74f1151540e4a79c2a7b50b4fa9d051bdc801d22413ee1c815e0df95f8c20185e98a8edce6e8909b276d0f3be3d3e5e3'
7
+ data.tar.gz: c23909dd4d2502a9ecd0e7ea8832d9611542af282230bd7c7b126bf76394a80acd14e8cf73be0362ea90875c63192cac4102878cfafab5cfc0419adfeb236a7d
data/CHANGELOG.md CHANGED
@@ -4,6 +4,24 @@ All notable changes to this project will be documented in this file.
4
4
  The format (since v2) is based on [Keep a Changelog v1](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning v2](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [2.0.6] - 2022-07-13
8
+ ### Fixed
9
+ - [#624](https://github.com/oauth-xx/oauth2/pull/624) - Fixes a [regression](https://github.com/oauth-xx/oauth2/pull/623) in v2.0.5, where an error would be raised in refresh_token flows due to (legitimate) lack of access_token (@pboling)
10
+
11
+ ## [2.0.5] - 2022-07-07
12
+ ### Fixed
13
+ - [#620](https://github.com/oauth-xx/oauth2/pull/620) - Documentation improvements, to help with upgrading (@swanson)
14
+ - [#621](https://github.com/oauth-xx/oauth2/pull/621) - Fixed [#528](https://github.com/oauth-xx/oauth2/issues/528) and [#619](https://github.com/oauth-xx/oauth2/issues/619) (@pboling)
15
+ - All data in responses is now returned, with the access token removed and set as `token`
16
+ - `refresh_token` is no longer dropped
17
+ - **BREAKING**: Microsoft's `id_token` is no longer left as `access_token['id_token']`, but moved to the standard `access_token.token` that all other strategies use
18
+ - Remove `parse` and `snaky` from options so they don't get included in response
19
+ - There is now 100% test coverage, for lines _and_ branches, and it will stay that way.
20
+
21
+ ## [2.0.4] - 2022-07-01
22
+ ### Fixed
23
+ - [#618](https://github.com/oauth-xx/oauth2/pull/618) - In some scenarios the `snaky` option default value was not applied (@pboling)
24
+
7
25
  ## [2.0.3] - 2022-06-28
8
26
  ### Added
9
27
  - [#611](https://github.com/oauth-xx/oauth2/pull/611) - Proper deprecation warnings for `extract_access_token` argument (@pboling)
@@ -61,6 +79,10 @@ and this project adheres to [Semantic Versioning v2](https://semver.org/spec/v2.
61
79
  - [#414](https://github.com/oauth-xx/oauth2/pull/414) - Use Base64.strict_encode64 instead of custom internal logic (@meganemura)
62
80
  - [#489](https://github.com/oauth-xx/oauth2/pull/489) - **BREAKING**: Default value for option `OAuth2::Client` - `:authorize_url` removed leading slash to work with relative paths by default (`'oauth/authorize'`) (@ghost)
63
81
  - [#489](https://github.com/oauth-xx/oauth2/pull/489) - **BREAKING**: Default value for option `OAuth2::Client` - `:token_url` removed leading slash to work with relative paths by default (`'oauth/token'`) (@ghost)
82
+ - [#507](https://github.com/oauth-xx/oauth2/pull/507), [#575](https://github.com/oauth-xx/oauth2/pull/575) - **BREAKING**: Transform keys to camel case, always, by default (ultimately via `rash_alt` gem)
83
+ - Original keys will still work as previously, in most scenarios, thanks to `rash_alt` gem.
84
+ - However, this is a _breaking_ change if you rely on `response.parsed.to_h`, as the keys in the result will be camel case.
85
+ - As of version 2.0.4 you can turn key transformation off with the `snaky: false` option.
64
86
  - [#576](https://github.com/oauth-xx/oauth2/pull/576) - **BREAKING**: Stop rescuing parsing errors (@pboling)
65
87
  - [#591](https://github.com/oauth-xx/oauth2/pull/576) - _DEPRECATION_: `OAuth2::Client` - `:extract_access_token` option is deprecated
66
88
  ### Fixed
@@ -90,6 +112,9 @@ and this project adheres to [Semantic Versioning v2](https://semver.org/spec/v2.
90
112
  - [#589](https://github.com/oauth-xx/oauth2/pull/589), [#593](https://github.com/oauth-xx/oauth2/pull/593) - Remove support for expired MAC token draft spec (@stanhu)
91
113
  - [#590](https://github.com/oauth-xx/oauth2/pull/590) - _Dependency_: Removed `multi_json` (@stanhu)
92
114
 
115
+ ## [1.4.10] - 2022-07-01
116
+ - FIPS Compatibility [#587](https://github.com/oauth-xx/oauth2/pull/587) (@akostadinov)
117
+
93
118
  ## [1.4.9] - 2022-02-20
94
119
  - Fixes compatibility with Faraday v2 [572](https://github.com/oauth-xx/oauth2/issues/572)
95
120
  - Includes supported versions of Faraday in test matrix:
@@ -100,7 +125,7 @@ and this project adheres to [Semantic Versioning v2](https://semver.org/spec/v2.
100
125
 
101
126
  ## [1.4.8] - 2022-02-18
102
127
  - MFA is now required to push new gem versions (@pboling)
103
- - README overhaul w/ new Ruby Verion and Engine compatibility policies (@pboling)
128
+ - README overhaul w/ new Ruby Version and Engine compatibility policies (@pboling)
104
129
  - [#569](https://github.com/oauth-xx/oauth2/pull/569) Backport fixes ([#561](https://github.com/oauth-xx/oauth2/pull/561) by @ryogift), and add more fixes, to allow faraday 1.x and 2.x (@jrochkind)
105
130
  - Improve Code Coverage tracking (Coveralls, CodeCov, CodeClimate), and enable branch coverage (@pboling)
106
131
  - Add CodeQL, Security Policy, Funding info (@pboling)
@@ -229,7 +254,6 @@ and this project adheres to [Semantic Versioning v2](https://semver.org/spec/v2.
229
254
 
230
255
  ## [0.0.4] + [0.0.3] + [0.0.2] + [0.0.1] - 2010-04-22
231
256
 
232
- [Unreleased]: https://github.com/oauth-xx/oauth2/compare/v2.0.3...HEAD
233
257
  [0.0.1]: https://github.com/oauth-xx/oauth2/compare/311d9f4...v0.0.1
234
258
  [0.0.2]: https://github.com/oauth-xx/oauth2/compare/v0.0.1...v0.0.2
235
259
  [0.0.3]: https://github.com/oauth-xx/oauth2/compare/v0.0.2...v0.0.3
@@ -265,8 +289,13 @@ and this project adheres to [Semantic Versioning v2](https://semver.org/spec/v2.
265
289
  [1.4.7]: https://github.com/oauth-xx/oauth2/compare/v1.4.6...v1.4.7
266
290
  [1.4.8]: https://github.com/oauth-xx/oauth2/compare/v1.4.7...v1.4.8
267
291
  [1.4.9]: https://github.com/oauth-xx/oauth2/compare/v1.4.8...v1.4.9
268
- [2.0.0]: https://github.com/oauth-xx/oauth2/compare/v1.4.9...v2.0.0
292
+ [1.4.10]: https://github.com/oauth-xx/oauth2/compare/v1.4.9...v1.4.10
293
+ [2.0.0]: https://github.com/oauth-xx/oauth2/compare/v1.4.10...v2.0.0
269
294
  [2.0.1]: https://github.com/oauth-xx/oauth2/compare/v2.0.0...v2.0.1
270
295
  [2.0.2]: https://github.com/oauth-xx/oauth2/compare/v2.0.1...v2.0.2
271
296
  [2.0.3]: https://github.com/oauth-xx/oauth2/compare/v2.0.2...v2.0.3
297
+ [2.0.4]: https://github.com/oauth-xx/oauth2/compare/v2.0.3...v2.0.4
298
+ [2.0.5]: https://github.com/oauth-xx/oauth2/compare/v2.0.4...v2.0.5
299
+ [2.0.6]: https://github.com/oauth-xx/oauth2/compare/v2.0.5...v2.0.6
300
+ [Unreleased]: https://github.com/oauth-xx/oauth2/compare/v2.0.6...HEAD
272
301
  [gemfiles/readme]: gemfiles/README.md
data/README.md CHANGED
@@ -32,6 +32,9 @@ See the sibling `oauth` gem for OAuth 1.0 implementations in Ruby.
32
32
 
33
33
  | Version | Release Date | Readme |
34
34
  |---------|--------------|----------------------------------------------------------|
35
+ | 2.0.6 | 2022-07-13 | https://github.com/oauth-xx/oauth2/blob/v2.0.6/README.md |
36
+ | 2.0.5 | 2022-07-07 | https://github.com/oauth-xx/oauth2/blob/v2.0.5/README.md |
37
+ | 2.0.4 | 2022-07-01 | https://github.com/oauth-xx/oauth2/blob/v2.0.4/README.md |
35
38
  | 2.0.3 | 2022-06-28 | https://github.com/oauth-xx/oauth2/blob/v2.0.3/README.md |
36
39
  | 2.0.2 | 2022-06-24 | https://github.com/oauth-xx/oauth2/blob/v2.0.2/README.md |
37
40
  | 2.0.1 | 2022-06-22 | https://github.com/oauth-xx/oauth2/blob/v2.0.1/README.md |
@@ -43,18 +46,19 @@ See the sibling `oauth` gem for OAuth 1.0 implementations in Ruby.
43
46
  <details>
44
47
  <summary>1.4.x Readmes</summary>
45
48
 
46
- | Version | Release Date | Readme |
47
- |---------|--------------|----------------------------------------------------------|
48
- | 1.4.9 | Feb 20, 2022 | https://github.com/oauth-xx/oauth2/blob/v1.4.9/README.md |
49
- | 1.4.8 | Feb 18, 2022 | https://github.com/oauth-xx/oauth2/blob/v1.4.8/README.md |
50
- | 1.4.7 | Mar 19, 2021 | https://github.com/oauth-xx/oauth2/blob/v1.4.7/README.md |
51
- | 1.4.6 | Mar 19, 2021 | https://github.com/oauth-xx/oauth2/blob/v1.4.6/README.md |
52
- | 1.4.5 | Mar 18, 2021 | https://github.com/oauth-xx/oauth2/blob/v1.4.5/README.md |
53
- | 1.4.4 | Feb 12, 2020 | https://github.com/oauth-xx/oauth2/blob/v1.4.4/README.md |
54
- | 1.4.3 | Jan 29, 2020 | https://github.com/oauth-xx/oauth2/blob/v1.4.3/README.md |
55
- | 1.4.2 | Oct 1, 2019 | https://github.com/oauth-xx/oauth2/blob/v1.4.2/README.md |
56
- | 1.4.1 | Oct 13, 2018 | https://github.com/oauth-xx/oauth2/blob/v1.4.1/README.md |
57
- | 1.4.0 | Jun 9, 2017 | https://github.com/oauth-xx/oauth2/blob/v1.4.0/README.md |
49
+ | Version | Release Date | Readme |
50
+ |---------|--------------|-----------------------------------------------------------|
51
+ | 1.4.10 | Jul 1, 2022 | https://github.com/oauth-xx/oauth2/blob/v1.4.10/README.md |
52
+ | 1.4.9 | Feb 20, 2022 | https://github.com/oauth-xx/oauth2/blob/v1.4.9/README.md |
53
+ | 1.4.8 | Feb 18, 2022 | https://github.com/oauth-xx/oauth2/blob/v1.4.8/README.md |
54
+ | 1.4.7 | Mar 19, 2021 | https://github.com/oauth-xx/oauth2/blob/v1.4.7/README.md |
55
+ | 1.4.6 | Mar 19, 2021 | https://github.com/oauth-xx/oauth2/blob/v1.4.6/README.md |
56
+ | 1.4.5 | Mar 18, 2021 | https://github.com/oauth-xx/oauth2/blob/v1.4.5/README.md |
57
+ | 1.4.4 | Feb 12, 2020 | https://github.com/oauth-xx/oauth2/blob/v1.4.4/README.md |
58
+ | 1.4.3 | Jan 29, 2020 | https://github.com/oauth-xx/oauth2/blob/v1.4.3/README.md |
59
+ | 1.4.2 | Oct 1, 2019 | https://github.com/oauth-xx/oauth2/blob/v1.4.2/README.md |
60
+ | 1.4.1 | Oct 13, 2018 | https://github.com/oauth-xx/oauth2/blob/v1.4.1/README.md |
61
+ | 1.4.0 | Jun 9, 2017 | https://github.com/oauth-xx/oauth2/blob/v1.4.0/README.md |
58
62
  </details>
59
63
 
60
64
  <details>
@@ -141,10 +145,10 @@ The link tokens in the following sections should be kept ordered by the row and
141
145
  [🖐prs-o-img]: https://img.shields.io/github/issues-pr/oauth-xx/oauth2
142
146
  [🧮prs-c]: https://github.com/oauth-xx/oauth2/pulls?q=is%3Apr+is%3Aclosed
143
147
  [🧮prs-c-img]: https://img.shields.io/github/issues-pr-closed/oauth-xx/oauth2
144
- [📗next♻️]: https://github.com/oauth-xx/oauth2/milestone/15
145
- [📗next-img♻️]: https://img.shields.io/github/milestones/progress/oauth-xx/oauth2/15?label=Next%20Version
148
+ [📗next♻️]: https://github.com/oauth-xx/oauth2/milestone/2
149
+ [📗next-img♻️]: https://img.shields.io/github/milestones/progress/oauth-xx/oauth2/2?label=Next%20Version
146
150
 
147
- <!-- 3️⃣ maintanence & linting -->
151
+ <!-- 3️⃣ maintenance & linting -->
148
152
  [⛳cclim-maint]: https://codeclimate.com/github/oauth-xx/oauth2/maintainability
149
153
  [⛳cclim-maint-img♻️]: https://api.codeclimate.com/v1/badges/688c612528ff90a46955/maintainability
150
154
  [🖇triage-help]: https://www.codetriage.com/oauth-xx/oauth2
@@ -229,7 +233,9 @@ If bundler is not being used to manage dependencies, install the gem by executin
229
233
 
230
234
  Available as part of the Tidelift Subscription.
231
235
 
232
- The maintainers of OAuth2 and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use. [Learn more.](https://tidelift.com/subscription/pkg/rubygems-oauth2?utm_source=rubygems-oauth2&utm_medium=referral&utm_campaign=enterprise)
236
+ The maintainers of OAuth2 and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use. [Learn more.][tidelift-ref]
237
+
238
+ [tidelift-ref]: https://tidelift.com/subscription/pkg/rubygems-oauth2?utm_source=rubygems-oauth2&utm_medium=referral&utm_campaign=enterprise
233
239
 
234
240
  ## Security contact information
235
241
 
@@ -253,6 +259,12 @@ For more see [SECURITY.md][🚎sec-pol].
253
259
  - `:access_token_class` (`AccessToken`); user specified class to use for all calls to `get_token`
254
260
  - Adds new option to `OAuth2::AccessToken#initialize`:
255
261
  - `:expires_latency` (`nil`); number of seconds by which AccessToken validity will be reduced to offset latency
262
+ - By default, keys are transformed to camel case.
263
+ - Original keys will still work as previously, in most scenarios, thanks to `rash_alt` gem.
264
+ - However, this is a _breaking_ change if you rely on `response.parsed.to_h`, as the keys in the result will be camel case.
265
+ - As of version 2.0.4 you can turn key transformation off with the `snaky: false` option.
266
+ - By default, the `:auth_scheme` is now `:basic_auth` (instead of `:request_body`)
267
+ - Third-party strategies and gems may need to be updated if a provider was requiring client id/secret in the request body
256
268
  - [... A lot more](https://github.com/oauth-xx/oauth2/blob/master/CHANGELOG.md#2.0.0)
257
269
 
258
270
  ## Compatibility
@@ -289,13 +301,13 @@ fashion. If critical issues for a particular implementation exist at the time
289
301
  of a major release, support for that Ruby version may be dropped.
290
302
  </details>
291
303
 
292
- | | Ruby OAuth 2 Version | Maintenance Branch | Supported Officially | Supported Unofficially | Supported Incidentally |
293
- |:----|----------------------|--------------------|-------------------------|------------------------|------------------------|
294
- | 1️⃣ | 2.0.x | `master` | 2.7, 3.0, 3.1 | 2.5, 2.6 | 2.2, 2.3, 2.4 |
295
- | 2️⃣ | 1.4.x | `1-4-stable` | 2.5, 2.6, 2.7, 3.0, 3.1 | 2.1, 2.2, 2.3, 2.4 | 1.9, 2.0 |
296
- | 3️⃣ | older | N/A | Best of luck to you! | Please upgrade! | |
304
+ | | Ruby OAuth2 Version | Maintenance Branch | Supported Officially | Supported Unofficially | Supported Incidentally |
305
+ |:----|---------------------|--------------------|-------------------------|------------------------|------------------------|
306
+ | 1️⃣ | 2.0.x | `master` | 2.7, 3.0, 3.1 | 2.5, 2.6 | 2.2, 2.3, 2.4 |
307
+ | 2️⃣ | 1.4.x | `1-4-stable` | 2.5, 2.6, 2.7, 3.0, 3.1 | 2.1, 2.2, 2.3, 2.4 | 1.9, 2.0 |
308
+ | 3️⃣ | older | N/A | Best of luck to you! | Please upgrade! | |
297
309
 
298
- NOTE: The 1.4 series will only receive critical bug and security updates.
310
+ NOTE: The 1.4 series will only receive critical security updates.
299
311
  See [SECURITY.md][🚎sec-pol]
300
312
 
301
313
  ## Usage Examples
@@ -513,7 +525,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
513
525
 
514
526
  See [CONTRIBUTING.md][contributing]
515
527
 
516
- [contributing]: https://github.com/oauth-xx/oauth2/blob/main/CONTRIBUTING.md
528
+ [contributing]: https://github.com/oauth-xx/oauth2/blob/master/CONTRIBUTING.md
517
529
 
518
530
  ## Contributors
519
531
 
@@ -2,18 +2,28 @@
2
2
 
3
3
  module OAuth2
4
4
  class AccessToken # rubocop:disable Metrics/ClassLength
5
+ TOKEN_KEYS_STR = %w[access_token id_token token accessToken idToken].freeze
6
+ TOKEN_KEYS_SYM = %i[access_token id_token token accessToken idToken].freeze
7
+ TOKEN_KEY_LOOKUP = TOKEN_KEYS_STR + TOKEN_KEYS_SYM
8
+
5
9
  attr_reader :client, :token, :expires_in, :expires_at, :expires_latency, :params
6
10
  attr_accessor :options, :refresh_token, :response
7
11
 
8
12
  class << self
9
13
  # Initializes an AccessToken from a Hash
10
14
  #
11
- # @param client [Client] the OAuth2::Client instance
12
- # @param hash [Hash] a hash of AccessToken property values
15
+ # @param [Client] client the OAuth2::Client instance
16
+ # @param [Hash] hash a hash of AccessToken property values
17
+ # @option hash [String] 'access_token', 'id_token', 'token', :access_token, :id_token, or :token the access token
13
18
  # @return [AccessToken] the initialized AccessToken
14
19
  def from_hash(client, hash)
15
- hash = hash.dup
16
- new(client, hash.delete('access_token') || hash.delete(:access_token) || hash.delete('token') || hash.delete(:token), hash)
20
+ fresh = hash.dup
21
+ supported_keys = fresh.keys & TOKEN_KEY_LOOKUP
22
+ key = supported_keys[0]
23
+ # Having too many is sus, and may lead to bugs. Having none is fine (e.g. refresh flow doesn't need a token).
24
+ warn("OAuth2::AccessToken.from_hash: `hash` contained more than one 'token' key (#{supported_keys}); using #{key.inspect}.") if supported_keys.length > 1
25
+ token = fresh.delete(key)
26
+ new(client, token, fresh)
17
27
  end
18
28
 
19
29
  # Initializes an AccessToken from a key/value application/x-www-form-urlencoded string
@@ -24,16 +34,12 @@ module OAuth2
24
34
  def from_kvform(client, kvform)
25
35
  from_hash(client, Rack::Utils.parse_query(kvform))
26
36
  end
27
-
28
- def contains_token?(hash)
29
- hash.key?('access_token') || hash.key?('id_token') || hash.key?('token')
30
- end
31
37
  end
32
38
 
33
39
  # Initialize an AccessToken
34
40
  #
35
41
  # @param [Client] client the OAuth2::Client instance
36
- # @param [String] token the Access Token value
42
+ # @param [String] token the Access Token value (optional, may not be used in refresh flows)
37
43
  # @param [Hash] opts the options to create the Access Token with
38
44
  # @option opts [String] :refresh_token (nil) the refresh_token value
39
45
  # @option opts [FixNum, String] :expires_in (nil) the number of seconds in which the AccessToken will expire
@@ -47,10 +53,20 @@ module OAuth2
47
53
  def initialize(client, token, opts = {})
48
54
  @client = client
49
55
  @token = token.to_s
56
+
50
57
  opts = opts.dup
51
58
  %i[refresh_token expires_in expires_at expires_latency].each do |arg|
52
59
  instance_variable_set("@#{arg}", opts.delete(arg) || opts.delete(arg.to_s))
53
60
  end
61
+ no_tokens = (@token.nil? || @token.empty?) && (@refresh_token.nil? || @refresh_token.empty?)
62
+ if no_tokens
63
+ if @client.options[:raise_errors]
64
+ error = Error.new(opts)
65
+ raise(error)
66
+ else
67
+ warn('OAuth2::AccessToken has no token')
68
+ end
69
+ end
54
70
  @expires_in ||= opts.delete('expires')
55
71
  @expires_in &&= @expires_in.to_i
56
72
  @expires_at &&= convert_expires_at(@expires_at)
@@ -95,7 +111,11 @@ module OAuth2
95
111
  params[:refresh_token] = refresh_token
96
112
  new_token = @client.get_token(params, access_token_opts)
97
113
  new_token.options = options
98
- new_token.refresh_token = refresh_token unless new_token.refresh_token
114
+ if new_token.refresh_token
115
+ # Keep it, if there is one
116
+ else
117
+ new_token.refresh_token = refresh_token
118
+ end
99
119
  new_token
100
120
  end
101
121
  # A compatibility alias
data/lib/oauth2/client.rb CHANGED
@@ -9,7 +9,7 @@ module OAuth2
9
9
 
10
10
  # The OAuth2::Client class
11
11
  class Client # rubocop:disable Metrics/ClassLength
12
- RESERVED_PARAM_KEYS = %w[headers parse].freeze
12
+ RESERVED_PARAM_KEYS = %w[body headers params parse snaky].freeze
13
13
 
14
14
  attr_reader :id, :secret, :site
15
15
  attr_accessor :options
@@ -108,7 +108,7 @@ module OAuth2
108
108
  # @option opts [Boolean] :raise_errors whether or not to raise an OAuth2::Error on 400+ status
109
109
  # code response for this request. Will default to client option
110
110
  # @option opts [Symbol] :parse @see Response::initialize
111
- # @option opts [Symbol] :snaky @see Response::initialize
111
+ # @option opts [true, false] :snaky (true) @see Response::initialize
112
112
  # @yield [req] @see Faraday::Connection#run_request
113
113
  def request(verb, url, opts = {}, &block)
114
114
  response = execute_request(verb, url, opts, &block)
@@ -149,7 +149,7 @@ module OAuth2
149
149
  #
150
150
  # @param params [Hash] a Hash of params for the token endpoint, except:
151
151
  # @option params [Symbol] :parse @see Response#initialize
152
- # @option params [true, false] :snaky @see Response#initialize
152
+ # @option params [true, false] :snaky (true) @see Response#initialize
153
153
  # @param access_token_opts [Hash] access token options, to pass to the AccessToken object
154
154
  # @param extract_access_token [Proc] proc that extracts the access token from the response (DEPRECATED)
155
155
  # @yield [req] @see Faraday::Connection#run_request
@@ -165,12 +165,14 @@ module OAuth2
165
165
  end
166
166
  end.to_h
167
167
 
168
+ parse = params.key?(:parse) ? params.delete(:parse) : Response::DEFAULT_OPTIONS[:parse]
169
+ snaky = params.key?(:snaky) ? params.delete(:snaky) : Response::DEFAULT_OPTIONS[:snaky]
170
+
168
171
  request_opts = {
169
172
  raise_errors: options[:raise_errors],
170
- parse: params.delete(:parse),
171
- snaky: params.delete(:snaky),
173
+ parse: parse,
174
+ snaky: snaky,
172
175
  }
173
-
174
176
  params = authenticator.apply(params)
175
177
  headers = params.delete(:headers) || {}
176
178
  if options[:token_method] == :post
@@ -267,7 +269,10 @@ module OAuth2
267
269
  raise TimeoutError, e
268
270
  end
269
271
 
270
- Response.new(response, parse: opts[:parse], snaky: opts[:snaky])
272
+ parse = opts.key?(:parse) ? opts.delete(:parse) : Response::DEFAULT_OPTIONS[:parse]
273
+ snaky = opts.key?(:snaky) ? opts.delete(:snaky) : Response::DEFAULT_OPTIONS[:snaky]
274
+
275
+ Response.new(response, parse: parse, snaky: snaky)
271
276
  end
272
277
 
273
278
  # Returns the authenticator object
@@ -294,7 +299,7 @@ module OAuth2
294
299
  access_token_class = options[:access_token_class]
295
300
  data = response.parsed
296
301
 
297
- unless data.is_a?(Hash) && access_token_class.contains_token?(data)
302
+ unless data.is_a?(Hash) && !data.empty?
298
303
  return unless options[:raise_errors]
299
304
 
300
305
  error = Error.new(response)
data/lib/oauth2/error.rb CHANGED
@@ -2,21 +2,29 @@
2
2
 
3
3
  module OAuth2
4
4
  class Error < StandardError
5
- attr_reader :response, :code, :description
5
+ attr_reader :response, :body, :code, :description
6
6
 
7
7
  # standard error codes include:
8
8
  # 'invalid_request', 'invalid_client', 'invalid_token', 'invalid_grant', 'unsupported_grant_type', 'invalid_scope'
9
+ # response might be a Response object, or the response.parsed hash
9
10
  def initialize(response)
10
11
  @response = response
11
- message_opts = {}
12
-
13
- if response.parsed.is_a?(Hash)
14
- @code = response.parsed['error']
15
- @description = response.parsed['error_description']
16
- message_opts = parse_error_description(@code, @description)
12
+ if response.respond_to?(:parsed)
13
+ if response.parsed.is_a?(Hash)
14
+ @code = response.parsed['error']
15
+ @description = response.parsed['error_description']
16
+ end
17
+ elsif response.is_a?(Hash)
18
+ @code = response['error']
19
+ @description = response['error_description']
17
20
  end
18
-
19
- super(error_message(response.body, message_opts))
21
+ @body = if response.respond_to?(:body)
22
+ response.body
23
+ else
24
+ @response
25
+ end
26
+ message_opts = parse_error_description(@code, @description)
27
+ super(error_message(@body, message_opts))
20
28
  end
21
29
 
22
30
  private
@@ -7,6 +7,10 @@ require 'rack'
7
7
  module OAuth2
8
8
  # OAuth2::Response class
9
9
  class Response
10
+ DEFAULT_OPTIONS = {
11
+ parse: :automatic,
12
+ snaky: true,
13
+ }.freeze
10
14
  attr_reader :response
11
15
  attr_accessor :options
12
16
 
@@ -80,7 +80,7 @@ module OAuth2
80
80
  assertion = build_assertion(claims, encoding_opts)
81
81
  params = build_request(assertion, request_opts)
82
82
 
83
- @client.get_token(params, response_opts.merge('refresh_token' => nil))
83
+ @client.get_token(params, response_opts)
84
84
  end
85
85
 
86
86
  private
@@ -25,7 +25,7 @@ module OAuth2
25
25
  #
26
26
  # @param [String] code The Authorization Code value
27
27
  # @param [Hash] params additional params
28
- # @param [Hash] opts options
28
+ # @param [Hash] opts access_token_opts, @see Client#get_token
29
29
  # @note that you must also provide a :redirect_uri with most OAuth 2.0 providers
30
30
  def get_token(code, params = {}, opts = {})
31
31
  params = {'grant_type' => 'authorization_code', 'code' => code}.merge(@client.redirection_params).merge(params)
@@ -19,7 +19,7 @@ module OAuth2
19
19
  # @param [Hash] opts options
20
20
  def get_token(params = {}, opts = {})
21
21
  params = params.merge('grant_type' => 'client_credentials')
22
- @client.get_token(params, opts.merge('refresh_token' => nil))
22
+ @client.get_token(params, opts)
23
23
  end
24
24
  end
25
25
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OAuth2
4
4
  module Version
5
- VERSION = '2.0.3'.freeze
5
+ VERSION = '2.0.6'.freeze
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oauth2
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Boling
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2022-06-28 00:00:00.000000000 Z
13
+ date: 2022-07-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
@@ -112,14 +112,14 @@ dependencies:
112
112
  requirements:
113
113
  - - "~>"
114
114
  - !ruby/object:Gem::Version
115
- version: '1.0'
115
+ version: '1.1'
116
116
  type: :runtime
117
117
  prerelease: false
118
118
  version_requirements: !ruby/object:Gem::Requirement
119
119
  requirements:
120
120
  - - "~>"
121
121
  - !ruby/object:Gem::Version
122
- version: '1.0'
122
+ version: '1.1'
123
123
  - !ruby/object:Gem::Dependency
124
124
  name: addressable
125
125
  requirement: !ruby/object:Gem::Requirement
@@ -307,13 +307,24 @@ licenses:
307
307
  - MIT
308
308
  metadata:
309
309
  homepage_uri: https://github.com/oauth-xx/oauth2
310
- source_code_uri: https://github.com/oauth-xx/oauth2/tree/v2.0.3
311
- changelog_uri: https://github.com/oauth-xx/oauth2/blob/v2.0.3/CHANGELOG.md
310
+ source_code_uri: https://github.com/oauth-xx/oauth2/tree/v2.0.6
311
+ changelog_uri: https://github.com/oauth-xx/oauth2/blob/v2.0.6/CHANGELOG.md
312
312
  bug_tracker_uri: https://github.com/oauth-xx/oauth2/issues
313
- documentation_uri: https://www.rubydoc.info/gems/oauth2/2.0.3
313
+ documentation_uri: https://www.rubydoc.info/gems/oauth2/2.0.6
314
314
  wiki_uri: https://github.com/oauth-xx/oauth2/wiki
315
315
  rubygems_mfa_required: 'true'
316
- post_install_message:
316
+ post_install_message: |2+
317
+
318
+ You have installed oauth2 version OAuth2::Version, congratulations!
319
+
320
+ There are BREAKING changes, but most will not encounter them, and updating your code should be easy!
321
+
322
+ Please see:
323
+ • https://github.com/oauth-xx/oauth2#what-is-new-for-v20
324
+ • https://github.com/oauth-xx/oauth2/blob/master/CHANGELOG.md
325
+
326
+ Please report issues, and support the project! Thanks, |7eter l-|. l3oling
327
+
317
328
  rdoc_options: []
318
329
  require_paths:
319
330
  - lib