oauth2 2.0.1 → 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: 0b2375593530f7a565bfe90a1534e6203bb178428ca3c9670a0dcd728cfa134a
4
- data.tar.gz: 04c8289d5202d2db4f12321fc7acda898a77931c1acee21cd5bdd3a7bcbec96a
3
+ metadata.gz: 50c8edb06960c0fcbdd726c2ef9e741840910c227891994393eb2d26decca35e
4
+ data.tar.gz: b022f74a86c53ea268c6fff23650b0a721e4b33950bf43acdb541f263fd6eb6d
5
5
  SHA512:
6
- metadata.gz: 78b0c341b7fa62f31227ca3217fd3db5ad9dd17c54b9a9bca492f6e4f6294f2db63d7a88a221b7d3fb671d646ee7fc85c7bd4808a82536448e7f13611a8a7598
7
- data.tar.gz: 0c2374b9c939fd0c021e25bfa81c23e033af5313e294f18f802431d4c192098ade257c2aeac131a11429525450b786cf894fa7d0cf50f8171395b2ca6ccb8bd0
6
+ metadata.gz: 8ea7cd4353651231682ba42c71df70bb223e9d9ffbdb1fa6b68e0b381d44db947082dedd1e006d679044dd67bf9546062959f5d114df8d8d18803ae04b53dbcf
7
+ data.tar.gz: 6046dc1b501152225fa49e4c6519b54a94ecf61254f2e7ac2dc042a712c2aab5ab84600296a559a24d97738acce83e32eeb513371dfafdc59a3dbac606b63fc7
data/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ 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.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
+
7
13
  ## [2.0.1] - 2022-06-22
8
14
  ### Added
9
15
  - Documentation improvements (@pboling)
@@ -29,7 +35,7 @@ and this project adheres to [Semantic Versioning v2](https://semver.org/spec/v2.
29
35
  - [#413](https://github.com/oauth-xx/oauth2/pull/413) - _Documentation_: License scan and report (@meganemura)
30
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)
31
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)
32
- - [#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)
33
39
  - [#550](https://github.com/oauth-xx/oauth2/pull/550) - Raise error if location header not present when redirecting (@stanhu)
34
40
  - [#552](https://github.com/oauth-xx/oauth2/pull/552) - Add missing `version.rb` require (@ahorek)
35
41
  - [#553](https://github.com/oauth-xx/oauth2/pull/553) - Support `application/problem+json` format (@janz93)
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,8 @@ 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.1 | 2022-06-22 | 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 |
38
37
  | 2.0.0 | 2022-06-21 | https://github.com/oauth-xx/oauth2/blob/v2.0.0/README.md |
39
38
  </details>
40
39
 
@@ -106,15 +105,15 @@ appended indicators:
106
105
  ♻️ - URL needs to be updated from SASS integration. Find / Replace is insufficient.
107
106
  -->
108
107
 
109
- | | Project | bundle add oauth2 |
110
- |:----|-----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
111
- | 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] |
112
- | 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] |
113
- | 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] |
114
- | 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] |
115
- | 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] |
116
- | 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] |
117
- | 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] |
118
117
 
119
118
  <!--
120
119
  The link tokens in the following sections should be kept ordered by the row and badge numbering scheme
@@ -141,8 +140,8 @@ The link tokens in the following sections should be kept ordered by the row and
141
140
  [🖐prs-o-img]: https://img.shields.io/github/issues-pr/oauth-xx/oauth2
142
141
  [🧮prs-c]: https://github.com/oauth-xx/oauth2/pulls?q=is%3Apr+is%3Aclosed
143
142
  [🧮prs-c-img]: https://img.shields.io/github/issues-pr-closed/oauth-xx/oauth2
144
- [📗next]: https://github.com/oauth-xx/oauth2/milestone/12
145
- [📗next-img]: https://img.shields.io/github/milestones/progress/oauth-xx/oauth2/12?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
146
145
 
147
146
  <!-- 3️⃣ maintanence & linting -->
148
147
  [⛳cclim-maint]: https://codeclimate.com/github/oauth-xx/oauth2/maintainability
@@ -421,17 +420,17 @@ access = client.client_credentials.get_token
421
420
  # Client Assertion Strategy
422
421
  # see: https://tools.ietf.org/html/rfc7523
423
422
  claimset = {
424
- :iss => "http://localhost:3001",
425
- :aud => "http://localhost:8080/oauth2/token",
426
- :sub => "me@example.com",
427
- :exp => Time.now.utc.to_i + 3600
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,
428
427
  }
429
428
  assertion_params = [claimset, 'HS256', 'secret_key']
430
429
  access = client.assertion.get_token(assertion_params)
431
430
 
432
431
  # The `access` (i.e. access token) is then used like so:
433
432
  access.token # actual access_token string, if you need it somewhere
434
- access.get("/api/stuff") # making api calls with access token
433
+ access.get('/api/stuff') # making api calls with access token
435
434
  ```
436
435
 
437
436
  If you want to specify additional headers to be sent out with the
@@ -487,7 +486,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
487
486
 
488
487
  ## Contributing
489
488
 
490
- 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.
491
490
 
492
491
  ## Code of Conduct
493
492
 
@@ -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)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OAuth2
4
4
  module Version
5
- VERSION = '2.0.1'.freeze
5
+ VERSION = '2.0.2'.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.1
4
+ version: 2.0.2
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-22 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.1
311
- changelog_uri: https://github.com/oauth-xx/oauth2/blob/v2.0.1/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.1
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: