oauth2 2.0.0.rc3 → 2.0.2

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: 0e2faffc19628919996428503133639534edbd8b3de6924811665c73bd24629d
4
- data.tar.gz: 20d14dffb4e3ef670ee62762d73cf64e1e8312520c57a6d6602a27f623a27da8
3
+ metadata.gz: 50c8edb06960c0fcbdd726c2ef9e741840910c227891994393eb2d26decca35e
4
+ data.tar.gz: b022f74a86c53ea268c6fff23650b0a721e4b33950bf43acdb541f263fd6eb6d
5
5
  SHA512:
6
- metadata.gz: 51e8ddd541f7197a3e6d08f35cfc09b7839218e3b4022bea854930fe49a78fe38f26c76c40f70be61f39282efa6c6a1ca7bcb5515a889dea6eb5bd9e3d6cb515
7
- data.tar.gz: 46fa2325488eb90f8133806f90a6a6eb734d1b9fd25998d5dfdb2e690babbfe30d0d6f5112e57e33fed64fbb50b1ca24d1ea922adc00cd2819a3746c703650c8
6
+ metadata.gz: 8ea7cd4353651231682ba42c71df70bb223e9d9ffbdb1fa6b68e0b381d44db947082dedd1e006d679044dd67bf9546062959f5d114df8d8d18803ae04b53dbcf
7
+ data.tar.gz: 6046dc1b501152225fa49e4c6519b54a94ecf61254f2e7ac2dc042a712c2aab5ab84600296a559a24d97738acce83e32eeb513371dfafdc59a3dbac606b63fc7
data/CHANGELOG.md CHANGED
@@ -4,7 +4,18 @@ 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.0.rc3] - 2022-06-16
7
+ ## [2.0.2] - 2022-06-24
8
+ ### Added
9
+ - [#604](https://github.com/oauth-xx/oauth2/pull/604) - Wrap `Faraday::TimeoutError` in `OAuth2::TimeoutError` (@stanhu)
10
+ - [#606](https://github.com/oauth-xx/oauth2/pull/606) - Ruby 2.7 deprecation warning fix: Move `access_token_class` parameter into `Client` constructor (@stanhu)
11
+ - [#607](https://github.com/oauth-xx/oauth2/pull/607) - CHANGELOG correction, reference to `OAuth2::ConnectionError` (@zavan)
12
+
13
+ ## [2.0.1] - 2022-06-22
14
+ ### Added
15
+ - Documentation improvements (@pboling)
16
+ - Increased test coverage to 99% (@pboling)
17
+
18
+ ## [2.0.0] - 2022-06-21
8
19
  ### Added
9
20
  - [#158](https://github.com/oauth-xx/oauth2/pull/158), [#344](https://github.com/oauth-xx/oauth2/pull/344) - Optionally pass raw response to parsers (@niels)
10
21
  - [#190](https://github.com/oauth-xx/oauth2/pull/190), [#332](https://github.com/oauth-xx/oauth2/pull/332), [#334](https://github.com/oauth-xx/oauth2/pull/334), [#335](https://github.com/oauth-xx/oauth2/pull/335), [#360](https://github.com/oauth-xx/oauth2/pull/360), [#426](https://github.com/oauth-xx/oauth2/pull/426), [#427](https://github.com/oauth-xx/oauth2/pull/427), [#461](https://github.com/oauth-xx/oauth2/pull/461) - Documentation (@josephpage, @pboling, @meganemura, @joshRpowell, @elliotcm)
@@ -24,7 +35,7 @@ and this project adheres to [Semantic Versioning v2](https://semver.org/spec/v2.
24
35
  - [#413](https://github.com/oauth-xx/oauth2/pull/413) - _Documentation_: License scan and report (@meganemura)
25
36
  - [#442](https://github.com/oauth-xx/oauth2/pull/442) - Option: `OAuth2::Client#initialize` - `:logger` (`::Logger.new($stdout)`) logger to use when OAUTH_DEBUG is enabled (for parity with `1-4-stable` branch) (@rthbound)
26
37
  - [#494](https://github.com/oauth-xx/oauth2/pull/494) - Support [OIDC 1.0 Private Key JWT](https://openid.net/specs/openid-connect-core-1_0.html#ClientAuthentication); based on the OAuth JWT assertion specification [(RFC 7523)](https://tools.ietf.org/html/rfc7523) (@SteveyblamWork)
27
- - [#549](https://github.com/oauth-xx/oauth2/pull/549) - Wrap `Faraday::ConnectionFailed` in `OAuth2::ConnectionFailed` (@nikkypx)
38
+ - [#549](https://github.com/oauth-xx/oauth2/pull/549) - Wrap `Faraday::ConnectionFailed` in `OAuth2::ConnectionError` (@nikkypx)
28
39
  - [#550](https://github.com/oauth-xx/oauth2/pull/550) - Raise error if location header not present when redirecting (@stanhu)
29
40
  - [#552](https://github.com/oauth-xx/oauth2/pull/552) - Add missing `version.rb` require (@ahorek)
30
41
  - [#553](https://github.com/oauth-xx/oauth2/pull/553) - Support `application/problem+json` format (@janz93)
@@ -210,7 +221,7 @@ and this project adheres to [Semantic Versioning v2](https://semver.org/spec/v2.
210
221
 
211
222
  ## [0.0.4] + [0.0.3] + [0.0.2] + [0.0.1] - 2010-04-22
212
223
 
213
- [Unreleased]: https://github.com/oauth-xx/oauth2/compare/v1.4.9...HEAD
224
+ [Unreleased]: https://github.com/oauth-xx/oauth2/compare/v2.0.0...HEAD
214
225
  [0.0.1]: https://github.com/oauth-xx/oauth2/compare/311d9f4...v0.0.1
215
226
  [0.0.2]: https://github.com/oauth-xx/oauth2/compare/v0.0.1...v0.0.2
216
227
  [0.0.3]: https://github.com/oauth-xx/oauth2/compare/v0.0.2...v0.0.3
@@ -246,4 +257,6 @@ and this project adheres to [Semantic Versioning v2](https://semver.org/spec/v2.
246
257
  [1.4.7]: https://github.com/oauth-xx/oauth2/compare/v1.4.6...v1.4.7
247
258
  [1.4.8]: https://github.com/oauth-xx/oauth2/compare/v1.4.7...v1.4.8
248
259
  [1.4.9]: https://github.com/oauth-xx/oauth2/compare/v1.4.8...v1.4.9
260
+ [2.0.0]: https://github.com/oauth-xx/oauth2/compare/v1.4.9...v2.0.0
261
+ [2.0.1]: https://github.com/oauth-xx/oauth2/compare/v2.0.0...v2.0.1
249
262
  [gemfiles/readme]: gemfiles/README.md
data/README.md CHANGED
@@ -22,8 +22,6 @@ See the sibling `oauth` gem for OAuth 1.0 implementations in Ruby.
22
22
 
23
23
  [oauth2-spec]: https://oauth.net/2/
24
24
  [sibling-gem]: https://github.com/oauth-xx/oauth-ruby
25
- [next-milestone-pct]: https://github.com/oauth-xx/oauth2/milestone/1
26
- [next-milestone-pct-img]: https://img.shields.io/github/milestones/progress-percent/oauth-xx/oauth2/1
27
25
 
28
26
  ## Release Documentation
29
27
 
@@ -34,7 +32,9 @@ See the sibling `oauth` gem for OAuth 1.0 implementations in Ruby.
34
32
 
35
33
  | Version | Release Date | Readme |
36
34
  |---------|--------------|----------------------------------------------------------|
37
- | 2.0.0 | Soon | https://github.com/oauth-xx/oauth2/blob/master/README.md |
35
+ | 2.0.2 | 2022-06-24 | https://github.com/oauth-xx/oauth2/blob/v2.0.2/README.md |
36
+ | 2.0.1 | 2022-06-22 | https://github.com/oauth-xx/oauth2/blob/v2.0.1/README.md |
37
+ | 2.0.0 | 2022-06-21 | https://github.com/oauth-xx/oauth2/blob/v2.0.0/README.md |
38
38
  </details>
39
39
 
40
40
  ### Older Releases
@@ -105,15 +105,15 @@ appended indicators:
105
105
  ♻️ - URL needs to be updated from SASS integration. Find / Replace is insufficient.
106
106
  -->
107
107
 
108
- | | Project | bundle add oauth2 |
109
- |:----|-----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
110
- | 1️⃣ | name, license, docs | [![RubyGems.org][⛳️name-img]][⛳️gem] [![License: MIT][🖇src-license-img]][🖇src-license] [![FOSSA][🏘fossa-img]][🏘fossa] [![RubyDoc.info][🚎yard-img]][🚎yard] [![InchCI][🖐inch-ci-img]][🚎yard] |
111
- | 2️⃣ | version & activity | [![Gem Version][⛳️version-img]][⛳️gem] [![Total Downloads][🖇DL-total-img]][⛳️gem] [![Download Rank][🏘DL-rank-img]][⛳️gem] [![Source Code][🚎src-home-img]][🚎src-home] [![Open PRs][🖐prs-o-img]][🖐prs-o] [![Closed PRs][🧮prs-c-img]][🧮prs-c] [![Next Version][📗next-img]][📗next] |
112
- | 3️⃣ | maintanence & linting | [![Maintainability][⛳cclim-maint-img♻️]][⛳cclim-maint] [![Helpers][🖇triage-help-img]][🖇triage-help] [![Depfu][🏘depfu-img♻️]][🏘depfu♻️] [![Contributors][🚎contributors-img]][🚎contributors] [![Style][🖐style-wf-img]][🖐style-wf] [![Kloc Roll][🧮kloc-img]][🧮kloc] |
113
- | 4️⃣ | testing | [![Open Issues][⛳iss-o-img]][⛳iss-o] [![Closed Issues][🖇iss-c-img]][🖇iss-c] [![Supported][🏘sup-wf-img]][🏘sup-wf] [![Heads][🚎heads-wf-img]][🚎heads-wf] [![Unofficial Support][🖐uns-wf-img]][🖐uns-wf] [![MacOS][🧮mac-wf-img]][🧮mac-wf] [![Windows][📗win-wf-img]][📗win-wf] |
114
- | 5️⃣ | coverage & security | [![CodeClimate][⛳cclim-cov-img♻️]][⛳cclim-cov] [![CodeCov][🖇codecov-img♻️]][🖇codecov] [![Coveralls][🏘coveralls-img]][🏘coveralls] [![Security Policy][🚎sec-pol-img]][🚎sec-pol] [![CodeQL][🖐codeQL-img]][🖐codeQL] [![Code Coverage][🧮cov-wf-img]][🧮cov-wf] |
115
- | 6️⃣ | resources | [![Discussion][⛳gh-discussions-img]][⛳gh-discussions] [![Get help on Codementor][🖇codementor-img]][🖇codementor] [![Chat][🏘chat-img]][🏘chat] [![Blog][🚎blog-img]][🚎blog] [![Blog][🖐wiki-img]][🖐wiki] |
116
- | 7️⃣ | spread 💖 | [![Liberapay Patrons][⛳liberapay-img]][⛳liberapay] [![Sponsor Me][🖇sponsor-img]][🖇sponsor] [![Tweet @ Peter][🏘tweet-img]][🏘tweet] [🌏][aboutme] [👼][angelme] [💻][coderme] [🌹][politicme] |
108
+ | | Project | bundle add oauth2 |
109
+ |:----|-----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
110
+ | 1️⃣ | name, license, docs | [![RubyGems.org][⛳️name-img]][⛳️gem] [![License: MIT][🖇src-license-img]][🖇src-license] [![FOSSA][🏘fossa-img]][🏘fossa] [![RubyDoc.info][🚎yard-img]][🚎yard] [![InchCI][🖐inch-ci-img]][🚎yard] |
111
+ | 2️⃣ | version & activity | [![Gem Version][⛳️version-img]][⛳️gem] [![Total Downloads][🖇DL-total-img]][⛳️gem] [![Download Rank][🏘DL-rank-img]][⛳️gem] [![Source Code][🚎src-home-img]][🚎src-home] [![Open PRs][🖐prs-o-img]][🖐prs-o] [![Closed PRs][🧮prs-c-img]][🧮prs-c] [![Next Version][📗next-img♻️]][📗next♻️] |
112
+ | 3️⃣ | maintanence & linting | [![Maintainability][⛳cclim-maint-img♻️]][⛳cclim-maint] [![Helpers][🖇triage-help-img]][🖇triage-help] [![Depfu][🏘depfu-img♻️]][🏘depfu♻️] [![Contributors][🚎contributors-img]][🚎contributors] [![Style][🖐style-wf-img]][🖐style-wf] [![Kloc Roll][🧮kloc-img]][🧮kloc] |
113
+ | 4️⃣ | testing | [![Open Issues][⛳iss-o-img]][⛳iss-o] [![Closed Issues][🖇iss-c-img]][🖇iss-c] [![Supported][🏘sup-wf-img]][🏘sup-wf] [![Heads][🚎heads-wf-img]][🚎heads-wf] [![Unofficial Support][🖐uns-wf-img]][🖐uns-wf] [![MacOS][🧮mac-wf-img]][🧮mac-wf] [![Windows][📗win-wf-img]][📗win-wf] |
114
+ | 5️⃣ | coverage & security | [![CodeClimate][⛳cclim-cov-img♻️]][⛳cclim-cov] [![CodeCov][🖇codecov-img♻️]][🖇codecov] [![Coveralls][🏘coveralls-img]][🏘coveralls] [![Security Policy][🚎sec-pol-img]][🚎sec-pol] [![CodeQL][🖐codeQL-img]][🖐codeQL] [![Code Coverage][🧮cov-wf-img]][🧮cov-wf] |
115
+ | 6️⃣ | resources | [![Discussion][⛳gh-discussions-img]][⛳gh-discussions] [![Get help on Codementor][🖇codementor-img]][🖇codementor] [![Chat][🏘chat-img]][🏘chat] [![Blog][🚎blog-img]][🚎blog] [![Blog][🖐wiki-img]][🖐wiki] |
116
+ | 7️⃣ | spread 💖 | [![Liberapay Patrons][⛳liberapay-img]][⛳liberapay] [![Sponsor Me][🖇sponsor-img]][🖇sponsor] [![Tweet @ Peter][🏘tweet-img]][🏘tweet] [🌏][aboutme] [👼][angelme] [💻][coderme] [🌹][politicme] |
117
117
 
118
118
  <!--
119
119
  The link tokens in the following sections should be kept ordered by the row and badge numbering scheme
@@ -140,8 +140,8 @@ The link tokens in the following sections should be kept ordered by the row and
140
140
  [🖐prs-o-img]: https://img.shields.io/github/issues-pr/oauth-xx/oauth2
141
141
  [🧮prs-c]: https://github.com/oauth-xx/oauth2/pulls?q=is%3Apr+is%3Aclosed
142
142
  [🧮prs-c-img]: https://img.shields.io/github/issues-pr-closed/oauth-xx/oauth2
143
- [📗next]: https://github.com/oauth-xx/oauth2/milestone/1
144
- [📗next-img]: https://img.shields.io/github/milestones/progress/oauth-xx/oauth2/1?label=Next%20Version
143
+ [📗next♻️]: https://github.com/oauth-xx/oauth2/milestone/14
144
+ [📗next-img♻️]: https://img.shields.io/github/milestones/progress/oauth-xx/oauth2/14?label=Next%20Version
145
145
 
146
146
  <!-- 3️⃣ maintanence & linting -->
147
147
  [⛳cclim-maint]: https://codeclimate.com/github/oauth-xx/oauth2/maintainability
@@ -238,7 +238,7 @@ Tidelift will coordinate the fix and disclosure.
238
238
 
239
239
  For more see [SECURITY.md][🚎sec-pol].
240
240
 
241
- ## What is new for v2.0 (unreleased, `master` branch)?
241
+ ## What is new for v2.0?
242
242
 
243
243
  - Officially support Ruby versions >= 2.7
244
244
  - Unofficially support Ruby versions >= 2.5
@@ -253,7 +253,7 @@ For more see [SECURITY.md][🚎sec-pol].
253
253
  - `:access_token_class` (`AccessToken`); user specified class to use for all calls to `get_token`
254
254
  - Adds new option to `OAuth2::AccessToken#initialize`:
255
255
  - `:expires_latency` (`nil`); number of seconds by which AccessToken validity will be reduced to offset latency
256
- - [... A lot more](https://github.com/oauth-xx/oauth2/blob/master/CHANGELOG.md#unreleased)
256
+ - [... A lot more](https://github.com/oauth-xx/oauth2/blob/master/CHANGELOG.md#2.0.0)
257
257
 
258
258
  ## Compatibility
259
259
 
@@ -291,7 +291,7 @@ of a major release, support for that Ruby version may be dropped.
291
291
 
292
292
  | | Ruby OAuth 2 Version | Maintenance Branch | Supported Officially | Supported Unofficially | Supported Incidentally |
293
293
  |:----|----------------------|--------------------|-------------------------|------------------------|------------------------|
294
- | 1️⃣ | 2.0.x (unreleased) | `master` | 2.7, 3.0, 3.1 | 2.5, 2.6 | 2.2, 2.3, 2.4 |
294
+ | 1️⃣ | 2.0.x | `master` | 2.7, 3.0, 3.1 | 2.5, 2.6 | 2.2, 2.3, 2.4 |
295
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
296
  | 3️⃣ | older | N/A | Best of luck to you! | Please upgrade! | |
297
297
 
@@ -309,8 +309,8 @@ client = OAuth2::Client.new('client_id', 'client_secret', site: 'https://example
309
309
  client.auth_code.authorize_url(redirect_uri: 'http://localhost:8080/oauth2/callback')
310
310
  # => "https://example.org/oauth/authorize?client_id=client_id&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Foauth2%2Fcallback&response_type=code"
311
311
 
312
- token = client.auth_code.get_token('authorization_code_value', redirect_uri: 'http://localhost:8080/oauth2/callback', headers: {'Authorization' => 'Basic some_password'})
313
- response = token.get('/api/resource', params: {'query_foo' => 'bar'})
312
+ access = client.auth_code.get_token('authorization_code_value', redirect_uri: 'http://localhost:8080/oauth2/callback', headers: {'Authorization' => 'Basic some_password'})
313
+ response = access.get('/api/resource', params: {'query_foo' => 'bar'})
314
314
  response.class.name
315
315
  # => OAuth2::Response
316
316
  ```
@@ -402,28 +402,42 @@ Response instance will contain the `OAuth2::Error` instance.
402
402
 
403
403
  Currently the Authorization Code, Implicit, Resource Owner Password Credentials, Client Credentials, and Assertion
404
404
  authentication grant types have helper strategy classes that simplify client
405
- use. They are available via the `#auth_code`, `#implicit`, `#password`, `#client_credentials`, and `#assertion` methods respectively.
405
+ use. They are available via the [`#auth_code`](https://github.com/oauth-xx/oauth2/blob/master/lib/oauth2/strategy/auth_code.rb), [`#implicit`](https://github.com/oauth-xx/oauth2/blob/master/lib/oauth2/strategy/implicit.rb), [`#password`](https://github.com/oauth-xx/oauth2/blob/master/lib/oauth2/strategy/password.rb), [`#client_credentials`](https://github.com/oauth-xx/oauth2/blob/master/lib/oauth2/strategy/client_credentials.rb), and [`#assertion`](https://github.com/oauth-xx/oauth2/blob/master/lib/oauth2/strategy/assertion.rb) methods respectively.
406
406
 
407
+ These aren't full examples, but demonstrative of the differences between usage for each strategy.
407
408
  ```ruby
408
409
  auth_url = client.auth_code.authorize_url(redirect_uri: 'http://localhost:8080/oauth/callback')
409
- token = client.auth_code.get_token('code_value', redirect_uri: 'http://localhost:8080/oauth/callback')
410
+ access = client.auth_code.get_token('code_value', redirect_uri: 'http://localhost:8080/oauth/callback')
410
411
 
411
412
  auth_url = client.implicit.authorize_url(redirect_uri: 'http://localhost:8080/oauth/callback')
412
413
  # get the token params in the callback and
413
- token = OAuth2::AccessToken.from_kvform(client, query_string)
414
-
415
- token = client.password.get_token('username', 'password')
416
-
417
- token = client.client_credentials.get_token
418
-
419
- token = client.assertion.get_token(assertion_params)
414
+ access = OAuth2::AccessToken.from_kvform(client, query_string)
415
+
416
+ access = client.password.get_token('username', 'password')
417
+
418
+ access = client.client_credentials.get_token
419
+
420
+ # Client Assertion Strategy
421
+ # see: https://tools.ietf.org/html/rfc7523
422
+ claimset = {
423
+ iss: 'http://localhost:3001',
424
+ aud: 'http://localhost:8080/oauth2/token',
425
+ sub: 'me@example.com',
426
+ exp: Time.now.utc.to_i + 3600,
427
+ }
428
+ assertion_params = [claimset, 'HS256', 'secret_key']
429
+ access = client.assertion.get_token(assertion_params)
430
+
431
+ # The `access` (i.e. access token) is then used like so:
432
+ access.token # actual access_token string, if you need it somewhere
433
+ access.get('/api/stuff') # making api calls with access token
420
434
  ```
421
435
 
422
436
  If you want to specify additional headers to be sent out with the
423
437
  request, add a 'headers' hash under 'params':
424
438
 
425
439
  ```ruby
426
- token = client.auth_code.get_token('code_value', redirect_uri: 'http://localhost:8080/oauth/callback', headers: {'Some' => 'Header'})
440
+ access = client.auth_code.get_token('code_value', redirect_uri: 'http://localhost:8080/oauth/callback', headers: {'Some' => 'Header'})
427
441
  ```
428
442
 
429
443
  You can always use the `#request` method on the `OAuth2::Client` instance to make
@@ -472,7 +486,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
472
486
 
473
487
  ## Contributing
474
488
 
475
- Bug reports and pull requests are welcome on GitHub at https://github.com/oauth-xx/oauth2. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
489
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/oauth-xx/oauth2](https://github.com/oauth-xx/oauth2). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
476
490
 
477
491
  ## Code of Conduct
478
492
 
data/SECURITY.md CHANGED
@@ -12,3 +12,9 @@
12
12
 
13
13
  To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security).
14
14
  Tidelift will coordinate the fix and disclosure.
15
+
16
+ ## OAuth2 for Enterprise
17
+
18
+ Available as part of the Tidelift Subscription.
19
+
20
+ 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&utm_term=repo)
@@ -88,12 +88,12 @@ module OAuth2
88
88
  #
89
89
  # @return [AccessToken] a new AccessToken
90
90
  # @note options should be carried over to the new AccessToken
91
- def refresh(params = {}, access_token_opts = {}, access_token_class: self.class)
91
+ def refresh(params = {}, access_token_opts = {})
92
92
  raise('A refresh_token is not available') unless refresh_token
93
93
 
94
94
  params[:grant_type] = 'refresh_token'
95
95
  params[:refresh_token] = refresh_token
96
- new_token = @client.get_token(params, access_token_opts, access_token_class: access_token_class)
96
+ new_token = @client.get_token(params, access_token_opts)
97
97
  new_token.options = options
98
98
  new_token.refresh_token = refresh_token unless new_token.refresh_token
99
99
  new_token
data/lib/oauth2/client.rb CHANGED
@@ -5,6 +5,8 @@ require 'logger'
5
5
 
6
6
  module OAuth2
7
7
  ConnectionError = Class.new(Faraday::ConnectionFailed)
8
+ TimeoutError = Class.new(Faraday::TimeoutError)
9
+
8
10
  # The OAuth2::Client class
9
11
  class Client # rubocop:disable Metrics/ClassLength
10
12
  RESERVED_PARAM_KEYS = %w[headers parse].freeze
@@ -31,6 +33,7 @@ module OAuth2
31
33
  # @option options [Boolean] :raise_errors (true) whether or not to raise an OAuth2::Error on responses with 400+ status codes
32
34
  # @option options [Logger] :logger (::Logger.new($stdout)) which logger to use when OAUTH_DEBUG is enabled
33
35
  # @option options [Proc] :extract_access_token proc that takes the client and the response Hash and extracts the access token from the response (DEPRECATED)
36
+ # @option options [Class] :access_token_class [Class] class of access token for easier subclassing OAuth2::AccessToken, @version 2.0+
34
37
  # @yield [builder] The Faraday connection builder
35
38
  def initialize(client_id, client_secret, options = {}, &block)
36
39
  opts = options.dup
@@ -49,6 +52,7 @@ module OAuth2
49
52
  max_redirects: 5,
50
53
  raise_errors: true,
51
54
  logger: ::Logger.new($stdout),
55
+ access_token_class: AccessToken,
52
56
  }.merge(opts)
53
57
  @options[:connection_opts][:ssl] = ssl if ssl
54
58
  end
@@ -106,18 +110,7 @@ module OAuth2
106
110
  # @option opts [Symbol] :parse @see Response::initialize
107
111
  # @yield [req] The Faraday request
108
112
  def request(verb, url, opts = {})
109
- url = connection.build_url(url).to_s
110
-
111
- begin
112
- response = connection.run_request(verb, url, opts[:body], opts[:headers]) do |req|
113
- req.params.update(opts[:params]) if opts[:params]
114
- yield(req) if block_given?
115
- end
116
- rescue Faraday::ConnectionFailed => e
117
- raise ConnectionError, e
118
- end
119
-
120
- response = Response.new(response, parse: opts[:parse])
113
+ response = execute_request(verb, url, opts)
121
114
 
122
115
  case response.status
123
116
  when 301, 302, 303, 307
@@ -156,9 +149,8 @@ module OAuth2
156
149
  # @param params [Hash] a Hash of params for the token endpoint
157
150
  # @param access_token_opts [Hash] access token options, to pass to the AccessToken object
158
151
  # @param extract_access_token [Proc] proc that extracts the access token from the response (DEPRECATED)
159
- # @param access_token_class [Class] class of access token for easier subclassing OAuth2::AccessToken, @version 2.0+
160
152
  # @return [AccessToken] the initialized AccessToken
161
- def get_token(params, access_token_opts = {}, extract_access_token = options[:extract_access_token], access_token_class: AccessToken)
153
+ def get_token(params, access_token_opts = {}, extract_access_token = options[:extract_access_token])
162
154
  params = params.map do |key, value|
163
155
  if RESERVED_PARAM_KEYS.include?(key)
164
156
  [key.to_sym, value]
@@ -188,7 +180,7 @@ module OAuth2
188
180
  if extract_access_token
189
181
  parse_response_with_legacy_extract(response, access_token_opts, extract_access_token)
190
182
  else
191
- parse_response(response, access_token_opts, access_token_class)
183
+ parse_response(response, access_token_opts)
192
184
  end
193
185
  end
194
186
 
@@ -250,6 +242,23 @@ module OAuth2
250
242
 
251
243
  private
252
244
 
245
+ def execute_request(verb, url, opts = {})
246
+ url = connection.build_url(url).to_s
247
+
248
+ begin
249
+ response = connection.run_request(verb, url, opts[:body], opts[:headers]) do |req|
250
+ req.params.update(opts[:params]) if opts[:params]
251
+ yield(req) if block_given?
252
+ end
253
+ rescue Faraday::ConnectionFailed => e
254
+ raise ConnectionError, e
255
+ rescue Faraday::TimeoutError => e
256
+ raise TimeoutError, e
257
+ end
258
+
259
+ Response.new(response, parse: opts[:parse])
260
+ end
261
+
253
262
  # Returns the authenticator object
254
263
  #
255
264
  # @return [Authenticator] the initialized Authenticator
@@ -270,7 +279,8 @@ module OAuth2
270
279
  nil
271
280
  end
272
281
 
273
- def parse_response(response, access_token_opts, access_token_class)
282
+ def parse_response(response, access_token_opts)
283
+ access_token_class = options[:access_token_class]
274
284
  data = response.parsed
275
285
 
276
286
  unless data.is_a?(Hash) && access_token_class.contains_token?(data)
@@ -15,7 +15,7 @@ module OAuth2
15
15
  #
16
16
  # claim_set = {
17
17
  # :iss => "http://localhost:3001",
18
- # :aud => "http://localhost:8080/oauth2/token"
18
+ # :aud => "http://localhost:8080/oauth2/token",
19
19
  # :sub => "me@example.com",
20
20
  # :exp => Time.now.utc.to_i + 3600,
21
21
  # }
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OAuth2
4
4
  module Version
5
- VERSION = '2.0.0.rc3'.freeze
5
+ VERSION = '2.0.2'.freeze
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oauth2
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.rc3
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Boling
8
- - Michael Bleigh
9
8
  - Erik Michaels-Ober
9
+ - Michael Bleigh
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2022-06-20 00:00:00.000000000 Z
13
+ date: 2022-06-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
@@ -307,10 +307,10 @@ 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.0.rc3
311
- changelog_uri: https://github.com/oauth-xx/oauth2/blob/v2.0.0.rc3/CHANGELOG.md
310
+ source_code_uri: https://github.com/oauth-xx/oauth2/tree/v2.0.2
311
+ changelog_uri: https://github.com/oauth-xx/oauth2/blob/v2.0.2/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.0.rc3
313
+ documentation_uri: https://www.rubydoc.info/gems/oauth2/2.0.2
314
314
  wiki_uri: https://github.com/oauth-xx/oauth2/wiki
315
315
  rubygems_mfa_required: 'true'
316
316
  post_install_message:
@@ -324,9 +324,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
324
324
  version: 2.2.0
325
325
  required_rubygems_version: !ruby/object:Gem::Requirement
326
326
  requirements:
327
- - - ">"
327
+ - - ">="
328
328
  - !ruby/object:Gem::Version
329
- version: 1.3.1
329
+ version: '0'
330
330
  requirements: []
331
331
  rubygems_version: 3.3.16
332
332
  signing_key: