oauth2 1.4.2 → 1.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -2
- data/CODE_OF_CONDUCT.md +105 -46
- data/README.md +33 -5
- data/lib/oauth2/access_token.rb +12 -4
- data/lib/oauth2/authenticator.rb +10 -0
- data/lib/oauth2/client.rb +63 -16
- data/lib/oauth2/mac_token.rb +10 -2
- data/lib/oauth2/response.rb +5 -3
- data/lib/oauth2/strategy/assertion.rb +3 -3
- data/lib/oauth2/strategy/password.rb +2 -2
- data/lib/oauth2/version.rb +9 -3
- data/spec/helper.rb +37 -0
- data/spec/oauth2/access_token_spec.rb +216 -0
- data/spec/oauth2/authenticator_spec.rb +84 -0
- data/spec/oauth2/client_spec.rb +506 -0
- data/spec/oauth2/mac_token_spec.rb +117 -0
- data/spec/oauth2/response_spec.rb +90 -0
- data/spec/oauth2/strategy/assertion_spec.rb +58 -0
- data/spec/oauth2/strategy/auth_code_spec.rb +107 -0
- data/spec/oauth2/strategy/base_spec.rb +5 -0
- data/spec/oauth2/strategy/client_credentials_spec.rb +69 -0
- data/spec/oauth2/strategy/implicit_spec.rb +26 -0
- data/spec/oauth2/strategy/password_spec.rb +55 -0
- data/spec/oauth2/version_spec.rb +23 -0
- metadata +41 -38
- data/.document +0 -5
- data/.gitignore +0 -19
- data/.jrubyrc +0 -1
- data/.rspec +0 -2
- data/.rubocop.yml +0 -80
- data/.rubocop_rspec.yml +0 -26
- data/.rubocop_todo.yml +0 -15
- data/.ruby-version +0 -1
- data/.travis.yml +0 -70
- data/CONTRIBUTING.md +0 -18
- data/Gemfile +0 -40
- data/Rakefile +0 -45
- data/gemfiles/jruby_1.7.gemfile +0 -11
- data/gemfiles/jruby_9.0.gemfile +0 -7
- data/gemfiles/jruby_9.1.gemfile +0 -3
- data/gemfiles/jruby_9.2.gemfile +0 -3
- data/gemfiles/jruby_head.gemfile +0 -3
- data/gemfiles/ruby_1.9.gemfile +0 -11
- data/gemfiles/ruby_2.0.gemfile +0 -6
- data/gemfiles/ruby_2.1.gemfile +0 -6
- data/gemfiles/ruby_2.2.gemfile +0 -3
- data/gemfiles/ruby_2.3.gemfile +0 -3
- data/gemfiles/ruby_2.4.gemfile +0 -3
- data/gemfiles/ruby_2.5.gemfile +0 -3
- data/gemfiles/ruby_2.6.gemfile +0 -9
- data/gemfiles/ruby_head.gemfile +0 -9
- data/gemfiles/truffleruby.gemfile +0 -3
- data/oauth2.gemspec +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74ca15f9b1935885fe123c9b0801b9f0605c1bfa904bebe371d201a61b559f31
|
4
|
+
data.tar.gz: 3b719ec6748493cba5112dfca8ebff22b13c0c9690330d4422f9d81b1abf5185
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ec3c9c311effac7f8864c2dc3d7332761ee6a986f2924adec3b77620abe3dc63984d1c01e9ca0a1283907a5b2ba23ee31dfd4bd630fa7d803fba116ba1e652d
|
7
|
+
data.tar.gz: 1e1d37d5953bdd7e03e13f697648e56afdb63ea54bbdbaee7ee229302149c5047c533a15d6498a355ef78d17d991d79ce8f94fe8728229431e3fad5c3132a9ad
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,33 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
-
##
|
4
|
+
## unreleased
|
5
5
|
|
6
|
-
|
6
|
+
## [1.4.7] - 2021-03-18
|
7
|
+
|
8
|
+
- [#541](https://github.com/oauth-xx/oauth2/pull/541) - Backport fix to expires_at handling [#533](https://github.com/oauth-xx/oauth2/pull/533) to 1-4-stable branch. (@dobon)
|
9
|
+
|
10
|
+
## [1.4.6] - 2021-03-18
|
11
|
+
|
12
|
+
- [#540](https://github.com/oauth-xx/oauth2/pull/540) - Add VERSION constant (@pboling)
|
13
|
+
- [#537](https://github.com/oauth-xx/oauth2/pull/537) - Fix crash in OAuth2::Client#get_token (@anderscarling)
|
14
|
+
- [#538](https://github.com/oauth-xx/oauth2/pull/538) - Remove reliance on globally included OAuth2 in tests for version 1.4 (@anderscarling)
|
15
|
+
|
16
|
+
## [1.4.5] - 2021-03-18
|
17
|
+
|
18
|
+
- [#535](https://github.com/oauth-xx/oauth2/pull/535) - Compatibility with range of supported Ruby OpenSSL versions, Rubocop updates, Github Actions (@pboling)
|
19
|
+
- [#518](https://github.com/oauth-xx/oauth2/pull/518) - Add extract_access_token option to OAuth2::Client (@jonspalmer)
|
20
|
+
|
21
|
+
## [1.4.4] - 2020-02-12
|
22
|
+
|
23
|
+
- [#408](https://github.com/oauth-xx/oauth2/pull/408) - Fixed expires_at for formatted time (@Lomey)
|
24
|
+
|
25
|
+
## [1.4.3] - 2020-01-29
|
26
|
+
|
27
|
+
- [#483](https://github.com/oauth-xx/oauth2/pull/483) - add project metadata to gemspec (@orien)
|
28
|
+
- [#495](https://github.com/oauth-xx/oauth2/pull/495) - support additional types of access token requests (@SteveyblamFreeagent, @thomcorley, @dgholz)
|
29
|
+
- Adds support for private_key_jwt and tls_client_auth
|
30
|
+
- [#433](https://github.com/oauth-xx/oauth2/pull/433) - allow field names with square brackets and numbers in params (@asm256)
|
7
31
|
|
8
32
|
## [1.4.2] - 2019-10-01
|
9
33
|
|
@@ -141,4 +165,6 @@ All notable changes to this project will be documented in this file.
|
|
141
165
|
[1.3.1]: https://github.com/oauth-xx/oauth2/compare/v1.3.0...v1.3.1
|
142
166
|
[1.4.0]: https://github.com/oauth-xx/oauth2/compare/v1.3.1...v1.4.0
|
143
167
|
[1.4.1]: https://github.com/oauth-xx/oauth2/compare/v1.4.0...v1.4.1
|
168
|
+
[1.4.2]: https://github.com/oauth-xx/oauth2/compare/v1.4.1...v1.4.2
|
169
|
+
[1.4.3]: https://github.com/oauth-xx/oauth2/compare/v1.4.2...v1.4.3
|
144
170
|
[unreleased]: https://github.com/oauth-xx/oauth2/compare/v1.4.1...HEAD
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,74 +1,133 @@
|
|
1
|
+
|
1
2
|
# Contributor Covenant Code of Conduct
|
2
3
|
|
3
4
|
## Our Pledge
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity
|
10
|
-
orientation.
|
6
|
+
We as members, contributors, and leaders pledge to make participation in our
|
7
|
+
community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
9
|
+
identity and expression, level of experience, education, socio-economic status,
|
10
|
+
nationality, personal appearance, race, religion, or sexual identity
|
11
|
+
and orientation.
|
12
|
+
|
13
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
14
|
+
diverse, inclusive, and healthy community.
|
11
15
|
|
12
16
|
## Our Standards
|
13
17
|
|
14
|
-
Examples of behavior that contributes to
|
15
|
-
include:
|
18
|
+
Examples of behavior that contributes to a positive environment for our
|
19
|
+
community include:
|
16
20
|
|
17
|
-
*
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
19
|
-
*
|
20
|
-
*
|
21
|
-
|
21
|
+
* Demonstrating empathy and kindness toward other people
|
22
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
23
|
+
* Giving and gracefully accepting constructive feedback
|
24
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
25
|
+
and learning from the experience
|
26
|
+
* Focusing on what is best not just for us as individuals, but for the
|
27
|
+
overall community
|
22
28
|
|
23
|
-
Examples of unacceptable behavior
|
29
|
+
Examples of unacceptable behavior include:
|
24
30
|
|
25
|
-
* The use of sexualized language or imagery and
|
26
|
-
advances
|
27
|
-
* Trolling, insulting
|
31
|
+
* The use of sexualized language or imagery, and sexual attention or
|
32
|
+
advances of any kind
|
33
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
28
34
|
* Public or private harassment
|
29
|
-
* Publishing others' private information, such as a physical or
|
30
|
-
address, without explicit permission
|
35
|
+
* Publishing others' private information, such as a physical or email
|
36
|
+
address, without their explicit permission
|
31
37
|
* Other conduct which could reasonably be considered inappropriate in a
|
32
38
|
professional setting
|
33
39
|
|
34
|
-
##
|
40
|
+
## Enforcement Responsibilities
|
35
41
|
|
36
|
-
|
37
|
-
behavior and
|
38
|
-
response to any
|
42
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
43
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
44
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
45
|
+
or harmful.
|
39
46
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
threatening, offensive, or harmful.
|
47
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
48
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
49
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
50
|
+
decisions when appropriate.
|
45
51
|
|
46
52
|
## Scope
|
47
53
|
|
48
|
-
This Code of Conduct applies
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
representative at an online or offline event.
|
53
|
-
further defined and clarified by project maintainers.
|
54
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
55
|
+
an individual is officially representing the community in public spaces.
|
56
|
+
Examples of representing our community include using an official e-mail address,
|
57
|
+
posting via an official social media account, or acting as an appointed
|
58
|
+
representative at an online or offline event.
|
54
59
|
|
55
60
|
## Enforcement
|
56
61
|
|
57
62
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
+
reported to the community leaders responsible for enforcement at
|
64
|
+
[INSERT CONTACT METHOD].
|
65
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
66
|
+
|
67
|
+
All community leaders are obligated to respect the privacy and security of the
|
68
|
+
reporter of any incident.
|
69
|
+
|
70
|
+
## Enforcement Guidelines
|
71
|
+
|
72
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
73
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
74
|
+
|
75
|
+
### 1. Correction
|
76
|
+
|
77
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
78
|
+
unprofessional or unwelcome in the community.
|
79
|
+
|
80
|
+
**Consequence**: A private, written warning from community leaders, providing
|
81
|
+
clarity around the nature of the violation and an explanation of why the
|
82
|
+
behavior was inappropriate. A public apology may be requested.
|
83
|
+
|
84
|
+
### 2. Warning
|
63
85
|
|
64
|
-
|
65
|
-
|
66
|
-
|
86
|
+
**Community Impact**: A violation through a single incident or series
|
87
|
+
of actions.
|
88
|
+
|
89
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
90
|
+
interaction with the people involved, including unsolicited interaction with
|
91
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
92
|
+
includes avoiding interactions in community spaces as well as external channels
|
93
|
+
like social media. Violating these terms may lead to a temporary or
|
94
|
+
permanent ban.
|
95
|
+
|
96
|
+
### 3. Temporary Ban
|
97
|
+
|
98
|
+
**Community Impact**: A serious violation of community standards, including
|
99
|
+
sustained inappropriate behavior.
|
100
|
+
|
101
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
102
|
+
communication with the community for a specified period of time. No public or
|
103
|
+
private interaction with the people involved, including unsolicited interaction
|
104
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
105
|
+
Violating these terms may lead to a permanent ban.
|
106
|
+
|
107
|
+
### 4. Permanent Ban
|
108
|
+
|
109
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
110
|
+
standards, including sustained inappropriate behavior, harassment of an
|
111
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
112
|
+
|
113
|
+
**Consequence**: A permanent ban from any sort of public interaction within
|
114
|
+
the community.
|
67
115
|
|
68
116
|
## Attribution
|
69
117
|
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
71
|
-
available at
|
118
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
119
|
+
version 2.0, available at
|
120
|
+
[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].
|
121
|
+
|
122
|
+
Community Impact Guidelines were inspired by
|
123
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
124
|
+
|
125
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
126
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available
|
127
|
+
at [https://www.contributor-covenant.org/translations][translations].
|
72
128
|
|
73
|
-
[homepage]:
|
74
|
-
[
|
129
|
+
[homepage]: https://www.contributor-covenant.org
|
130
|
+
[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
|
131
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
132
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
133
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/README.md
CHANGED
@@ -1,10 +1,30 @@
|
|
1
1
|
# OAuth2
|
2
2
|
|
3
|
+
If you need the readme for a released version of the gem please find it below:
|
4
|
+
|
5
|
+
| Version | Release Date | Readme |
|
6
|
+
|----------|--------------|----------------------------------------------------------|
|
7
|
+
| 1.4.7 | Mar 18, 2021 | https://github.com/oauth-xx/oauth2/blob/v1.4.7/README.md |
|
8
|
+
| 1.4.6 | Mar 18, 2021 | https://github.com/oauth-xx/oauth2/blob/v1.4.6/README.md |
|
9
|
+
| 1.4.5 | Mar 18, 2021 | https://github.com/oauth-xx/oauth2/blob/v1.4.5/README.md |
|
10
|
+
| 1.4.4 | Feb 12, 2020 | https://github.com/oauth-xx/oauth2/blob/v1.4.4/README.md |
|
11
|
+
| 1.4.3 | Jan 29, 2020 | https://github.com/oauth-xx/oauth2/blob/v1.4.3/README.md |
|
12
|
+
| 1.4.2 | Oct 1, 2019 | https://github.com/oauth-xx/oauth2/blob/v1.4.2/README.md |
|
13
|
+
| 1.4.1 | Oct 13, 2018 | https://github.com/oauth-xx/oauth2/blob/v1.4.1/README.md |
|
14
|
+
| 1.4.0 | Jun 9, 2017 | https://github.com/oauth-xx/oauth2/blob/v1.4.0/README.md |
|
15
|
+
| 1.3.1 | Mar 3, 2017 | https://github.com/oauth-xx/oauth2/blob/v1.3.1/README.md |
|
16
|
+
| 1.3.0 | Dec 27, 2016 | https://github.com/oauth-xx/oauth2/blob/v1.3.0/README.md |
|
17
|
+
| 1.2.0 | Jun 30, 2016 | https://github.com/oauth-xx/oauth2/blob/v1.2.0/README.md |
|
18
|
+
| 1.1.0 | Jan 30, 2016 | https://github.com/oauth-xx/oauth2/blob/v1.1.0/README.md |
|
19
|
+
| 1.0.0 | May 23, 2014 | https://github.com/oauth-xx/oauth2/blob/v1.0.0/README.md |
|
20
|
+
| < 1.0.0 | Find here | https://github.com/oauth-xx/oauth2/tags |
|
21
|
+
|
3
22
|
[][gem]
|
4
23
|
[][gem]
|
5
24
|
[][gem]
|
6
25
|
[][travis]
|
7
|
-
[][github-actions]
|
27
|
+
[][codeclimate-coverage]
|
8
28
|
[][codeclimate-maintainability]
|
9
29
|
[][depfu]
|
10
30
|
[][code-triage]
|
@@ -14,12 +34,15 @@
|
|
14
34
|
|
15
35
|
[gem]: https://rubygems.org/gems/oauth2
|
16
36
|
[travis]: http://travis-ci.org/oauth-xx/oauth2
|
37
|
+
[github-actions]: https://actions-badge.atrox.dev/oauth-xx/oauth2/goto
|
17
38
|
[coveralls]: https://coveralls.io/r/oauth-xx/oauth2
|
18
39
|
[codeclimate-maintainability]: https://codeclimate.com/github/oauth-xx/oauth2/maintainability
|
40
|
+
[codeclimate-coverage]: https://codeclimate.com/github/oauth-xx/oauth2/test_coverage
|
19
41
|
[depfu]: https://depfu.com/github/oauth-xx/oauth2
|
20
42
|
[source-license]: https://opensource.org/licenses/MIT
|
21
43
|
[inch-ci]: http://inch-ci.org/github/oauth-xx/oauth2
|
22
44
|
[code-triage]: https://www.codetriage.com/oauth-xx/oauth2
|
45
|
+
[fossa1]: https://app.fossa.io/projects/git%2Bgithub.com%2Foauth-xx%2Foauth2?ref=badge_shield
|
23
46
|
|
24
47
|
A Ruby wrapper for the [OAuth 2.0 specification][oauth2-spec].
|
25
48
|
|
@@ -49,7 +72,7 @@ Or install it yourself as:
|
|
49
72
|
|
50
73
|
[code]: https://github.com/oauth-xx/oauth2
|
51
74
|
[issues]: https://github.com/oauth-xx/oauth2/issues
|
52
|
-
[wiki]: https://github.com/oauth-xx/oauth2
|
75
|
+
[wiki]: https://wiki.github.com/oauth-xx/oauth2
|
53
76
|
|
54
77
|
## Usage Examples
|
55
78
|
|
@@ -61,11 +84,12 @@ client.auth_code.authorize_url(:redirect_uri => 'http://localhost:8080/oauth2/ca
|
|
61
84
|
# => "https://example.org/oauth/authorization?response_type=code&client_id=client_id&redirect_uri=http://localhost:8080/oauth2/callback"
|
62
85
|
|
63
86
|
token = client.auth_code.get_token('authorization_code_value', :redirect_uri => 'http://localhost:8080/oauth2/callback', :headers => {'Authorization' => 'Basic some_password'})
|
64
|
-
response = token.get('/api/resource', :params => {
|
87
|
+
response = token.get('/api/resource', :params => {'query_foo' => 'bar'})
|
65
88
|
response.class.name
|
66
89
|
# => OAuth2::Response
|
67
90
|
```
|
68
91
|
## OAuth2::Response
|
92
|
+
|
69
93
|
The AccessToken methods #get, #post, #put and #delete and the generic #request
|
70
94
|
will return an instance of the #OAuth2::Response class.
|
71
95
|
|
@@ -78,12 +102,14 @@ The original response body, headers, and status can be accessed via their
|
|
78
102
|
respective methods.
|
79
103
|
|
80
104
|
## OAuth2::AccessToken
|
105
|
+
|
81
106
|
If you have an existing Access Token for a user, you can initialize an instance
|
82
107
|
using various class methods including the standard new, from_hash (if you have
|
83
108
|
a hash of the values), or from_kvform (if you have an
|
84
109
|
application/x-www-form-urlencoded encoded string of the values).
|
85
110
|
|
86
111
|
## OAuth2::Error
|
112
|
+
|
87
113
|
On 400+ status code responses, an OAuth2::Error will be raised. If it is a
|
88
114
|
standard OAuth2 error response, the body will be parsed and #code and #description will contain the values provided from the error and
|
89
115
|
error_description parameters. The #response property of OAuth2::Error will
|
@@ -95,6 +121,7 @@ instance will be returned as usual and on 400+ status code responses, the
|
|
95
121
|
Response instance will contain the OAuth2::Error instance.
|
96
122
|
|
97
123
|
## Authorization Grants
|
124
|
+
|
98
125
|
Currently the Authorization Code, Implicit, Resource Owner Password Credentials, Client Credentials, and Assertion
|
99
126
|
authentication grant types have helper strategy classes that simplify client
|
100
127
|
use. They are available via the #auth_code, #implicit, #password, #client_credentials, and #assertion methods respectively.
|
@@ -144,12 +171,13 @@ implementations:
|
|
144
171
|
|
145
172
|
* Ruby 2.2 - Support ends with version 2.x series
|
146
173
|
* Ruby 2.3 - Support ends with version 3.x series
|
147
|
-
- [JRuby 9.1][jruby-9.1] (targets MRI v2.3)
|
174
|
+
- [JRuby 9.1][jruby-9.1] (targets MRI v2.3)
|
148
175
|
* Ruby 2.4 - Support ends with version 4.x series
|
149
176
|
* Ruby 2.5 - Support ends with version 5.x series
|
150
177
|
- [JRuby 9.2][jruby-9.2] (targets MRI v2.5)
|
151
178
|
- [truffleruby][truffleruby] (targets MRI 2.5)
|
152
179
|
* Ruby 2.6 - Support ends with version 6.x series
|
180
|
+
* Ruby 2.7 - Support ends with version 7.x series
|
153
181
|
|
154
182
|
[jruby-1.7]: https://www.jruby.org/2017/05/11/jruby-1-7-27.html
|
155
183
|
[jruby-9.0]: https://www.jruby.org/2016/01/26/jruby-9-0-5-0.html
|
@@ -207,7 +235,7 @@ spec.add_dependency 'oauth2', '~> 1.4'
|
|
207
235
|
|
208
236
|
## Development
|
209
237
|
|
210
|
-
After checking out the repo, run `
|
238
|
+
After checking out the repo, run `bundle install` to install dependencies. Then, run `rake spec` to run the tests.
|
211
239
|
|
212
240
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
213
241
|
|
data/lib/oauth2/access_token.rb
CHANGED
@@ -3,6 +3,7 @@ module OAuth2
|
|
3
3
|
attr_reader :client, :token, :expires_in, :expires_at, :params
|
4
4
|
attr_accessor :options, :refresh_token
|
5
5
|
|
6
|
+
# Should these methods be deprecated?
|
6
7
|
class << self
|
7
8
|
# Initializes an AccessToken from a Hash
|
8
9
|
#
|
@@ -46,11 +47,11 @@ module OAuth2
|
|
46
47
|
end
|
47
48
|
@expires_in ||= opts.delete('expires')
|
48
49
|
@expires_in &&= @expires_in.to_i
|
49
|
-
@expires_at &&= @expires_at
|
50
|
+
@expires_at &&= convert_expires_at(@expires_at)
|
50
51
|
@expires_at ||= Time.now.to_i + @expires_in if @expires_in
|
51
|
-
@options = {:mode
|
52
|
+
@options = {:mode => opts.delete(:mode) || :header,
|
52
53
|
:header_format => opts.delete(:header_format) || 'Bearer %s',
|
53
|
-
:param_name
|
54
|
+
:param_name => opts.delete(:param_name) || 'access_token'}
|
54
55
|
@params = opts
|
55
56
|
end
|
56
57
|
|
@@ -81,6 +82,7 @@ module OAuth2
|
|
81
82
|
# @note options should be carried over to the new AccessToken
|
82
83
|
def refresh!(params = {})
|
83
84
|
raise('A refresh_token is not available') unless refresh_token
|
85
|
+
|
84
86
|
params[:grant_type] = 'refresh_token'
|
85
87
|
params[:refresh_token] = refresh_token
|
86
88
|
new_token = @client.get_token(params)
|
@@ -149,7 +151,7 @@ module OAuth2
|
|
149
151
|
|
150
152
|
private
|
151
153
|
|
152
|
-
def configure_authentication!(opts) # rubocop:disable
|
154
|
+
def configure_authentication!(opts) # rubocop:disable Metrics/AbcSize
|
153
155
|
case options[:mode]
|
154
156
|
when :header
|
155
157
|
opts[:headers] ||= {}
|
@@ -169,5 +171,11 @@ module OAuth2
|
|
169
171
|
raise("invalid :mode option of #{options[:mode]}")
|
170
172
|
end
|
171
173
|
end
|
174
|
+
|
175
|
+
def convert_expires_at(expires_at)
|
176
|
+
Time.iso8601(expires_at.to_s).to_i
|
177
|
+
rescue ArgumentError
|
178
|
+
expires_at.to_i
|
179
|
+
end
|
172
180
|
end
|
173
181
|
end
|
data/lib/oauth2/authenticator.rb
CHANGED
@@ -25,6 +25,10 @@ module OAuth2
|
|
25
25
|
apply_basic_auth(params)
|
26
26
|
when :request_body
|
27
27
|
apply_params_auth(params)
|
28
|
+
when :tls_client_auth
|
29
|
+
apply_client_id(params)
|
30
|
+
when :private_key_jwt
|
31
|
+
params
|
28
32
|
else
|
29
33
|
raise NotImplementedError
|
30
34
|
end
|
@@ -42,6 +46,12 @@ module OAuth2
|
|
42
46
|
{'client_id' => id, 'client_secret' => secret}.merge(params)
|
43
47
|
end
|
44
48
|
|
49
|
+
# When using schemes that don't require the client_secret to be passed i.e TLS Client Auth,
|
50
|
+
# we don't want to send the secret
|
51
|
+
def apply_client_id(params)
|
52
|
+
{'client_id' => id}.merge(params)
|
53
|
+
end
|
54
|
+
|
45
55
|
# Adds an `Authorization` header with Basic Auth credentials if and only if
|
46
56
|
# it is not already set in the params.
|
47
57
|
def apply_basic_auth(params)
|
data/lib/oauth2/client.rb
CHANGED
@@ -4,6 +4,8 @@ require 'logger'
|
|
4
4
|
module OAuth2
|
5
5
|
# The OAuth2::Client class
|
6
6
|
class Client # rubocop:disable Metrics/ClassLength
|
7
|
+
RESERVED_PARAM_KEYS = %w[headers parse].freeze
|
8
|
+
|
7
9
|
attr_reader :id, :secret, :site
|
8
10
|
attr_accessor :options
|
9
11
|
attr_writer :connection
|
@@ -23,8 +25,8 @@ module OAuth2
|
|
23
25
|
# @option opts [Symbol] :auth_scheme (:basic_auth) HTTP method to use to authorize request (:basic_auth or :request_body)
|
24
26
|
# @option opts [Hash] :connection_opts ({}) Hash of connection options to pass to initialize Faraday with
|
25
27
|
# @option opts [FixNum] :max_redirects (5) maximum number of redirects to follow
|
26
|
-
# @option opts [Boolean] :raise_errors (true) whether or not to raise an OAuth2::Error
|
27
|
-
#
|
28
|
+
# @option opts [Boolean] :raise_errors (true) whether or not to raise an OAuth2::Error on responses with 400+ status codes
|
29
|
+
# @option opts [Proc] :extract_access_token proc that extracts the access token from the response
|
28
30
|
# @yield [builder] The Faraday connection builder
|
29
31
|
def initialize(client_id, client_secret, options = {}, &block)
|
30
32
|
opts = options.dup
|
@@ -32,14 +34,18 @@ module OAuth2
|
|
32
34
|
@secret = client_secret
|
33
35
|
@site = opts.delete(:site)
|
34
36
|
ssl = opts.delete(:ssl)
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
|
38
|
+
@options = {
|
39
|
+
:authorize_url => '/oauth/authorize',
|
40
|
+
:token_url => '/oauth/token',
|
41
|
+
:token_method => :post,
|
42
|
+
:auth_scheme => :request_body,
|
43
|
+
:connection_opts => {},
|
44
|
+
:connection_build => block,
|
45
|
+
:max_redirects => 5,
|
46
|
+
:raise_errors => true,
|
47
|
+
:extract_access_token => DEFAULT_EXTRACT_ACCESS_TOKEN,
|
48
|
+
}.merge(opts)
|
43
49
|
@options[:connection_opts][:ssl] = ssl if ssl
|
44
50
|
end
|
45
51
|
|
@@ -91,12 +97,13 @@ module OAuth2
|
|
91
97
|
# code response for this request. Will default to client option
|
92
98
|
# @option opts [Symbol] :parse @see Response::initialize
|
93
99
|
# @yield [req] The Faraday request
|
94
|
-
def request(verb, url, opts = {}) # rubocop:disable
|
100
|
+
def request(verb, url, opts = {}) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
95
101
|
connection.response :logger, ::Logger.new($stdout) if ENV['OAUTH_DEBUG'] == 'true'
|
96
102
|
|
97
|
-
url = connection.build_url(url
|
103
|
+
url = connection.build_url(url).to_s
|
98
104
|
|
99
105
|
response = connection.run_request(verb, url, opts[:body], opts[:headers]) do |req|
|
106
|
+
req.params.update(opts[:params]) if opts[:params]
|
100
107
|
yield(req) if block_given?
|
101
108
|
end
|
102
109
|
response = Response.new(response, :parse => opts[:parse])
|
@@ -106,6 +113,7 @@ module OAuth2
|
|
106
113
|
opts[:redirect_count] ||= 0
|
107
114
|
opts[:redirect_count] += 1
|
108
115
|
return response if opts[:redirect_count] > options[:max_redirects]
|
116
|
+
|
109
117
|
if response.status == 303
|
110
118
|
verb = :get
|
111
119
|
opts.delete(:body)
|
@@ -117,6 +125,7 @@ module OAuth2
|
|
117
125
|
when 400..599
|
118
126
|
error = Error.new(response)
|
119
127
|
raise(error) if opts.fetch(:raise_errors, options[:raise_errors])
|
128
|
+
|
120
129
|
response.error = error
|
121
130
|
response
|
122
131
|
else
|
@@ -130,8 +139,17 @@ module OAuth2
|
|
130
139
|
# @param [Hash] params a Hash of params for the token endpoint
|
131
140
|
# @param [Hash] access token options, to pass to the AccessToken object
|
132
141
|
# @param [Class] class of access token for easier subclassing OAuth2::AccessToken
|
133
|
-
# @return [AccessToken] the
|
134
|
-
def get_token(params, access_token_opts = {},
|
142
|
+
# @return [AccessToken] the initialized AccessToken
|
143
|
+
def get_token(params, access_token_opts = {}, extract_access_token = options[:extract_access_token]) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
144
|
+
params = params.map do |key, value|
|
145
|
+
if RESERVED_PARAM_KEYS.include?(key)
|
146
|
+
[key.to_sym, value]
|
147
|
+
else
|
148
|
+
[key, value]
|
149
|
+
end
|
150
|
+
end
|
151
|
+
params = Hash[params]
|
152
|
+
|
135
153
|
params = Authenticator.new(id, secret, options[:auth_scheme]).apply(params)
|
136
154
|
opts = {:raise_errors => options[:raise_errors], :parse => params.delete(:parse)}
|
137
155
|
headers = params.delete(:headers) || {}
|
@@ -144,11 +162,18 @@ module OAuth2
|
|
144
162
|
end
|
145
163
|
opts[:headers].merge!(headers)
|
146
164
|
response = request(options[:token_method], token_url, opts)
|
147
|
-
|
165
|
+
|
166
|
+
access_token = begin
|
167
|
+
build_access_token(response, access_token_opts, extract_access_token)
|
168
|
+
rescue StandardError
|
169
|
+
nil
|
170
|
+
end
|
171
|
+
|
172
|
+
if options[:raise_errors] && !access_token
|
148
173
|
error = Error.new(response)
|
149
174
|
raise(error)
|
150
175
|
end
|
151
|
-
|
176
|
+
access_token
|
152
177
|
end
|
153
178
|
|
154
179
|
# The Authorization Code strategy
|
@@ -206,5 +231,27 @@ module OAuth2
|
|
206
231
|
{}
|
207
232
|
end
|
208
233
|
end
|
234
|
+
|
235
|
+
DEFAULT_EXTRACT_ACCESS_TOKEN = proc do |client, hash|
|
236
|
+
token = hash.delete('access_token') || hash.delete(:access_token)
|
237
|
+
token && AccessToken.new(client, token, hash)
|
238
|
+
end
|
239
|
+
|
240
|
+
private
|
241
|
+
|
242
|
+
def build_access_token(response, access_token_opts, extract_access_token)
|
243
|
+
parsed_response = response.parsed.dup
|
244
|
+
return unless parsed_response.is_a?(Hash)
|
245
|
+
|
246
|
+
hash = parsed_response.merge(access_token_opts)
|
247
|
+
|
248
|
+
# Provide backwards compatibility for old AcessToken.form_hash pattern
|
249
|
+
# Should be deprecated in 2.x
|
250
|
+
if extract_access_token.is_a?(Class) && extract_access_token.respond_to?(:from_hash)
|
251
|
+
extract_access_token.from_hash(self, hash)
|
252
|
+
else
|
253
|
+
extract_access_token.call(self, hash)
|
254
|
+
end
|
255
|
+
end
|
209
256
|
end
|
210
257
|
end
|