oauth2 1.4.0 → 1.4.8
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 +5 -5
- data/CHANGELOG.md +187 -0
- data/CODE_OF_CONDUCT.md +133 -0
- data/LICENSE +22 -0
- data/README.md +336 -61
- data/lib/oauth2/access_token.rb +12 -4
- data/lib/oauth2/authenticator.rb +10 -0
- data/lib/oauth2/client.rb +67 -23
- data/lib/oauth2/error.rb +1 -1
- data/lib/oauth2/mac_token.rb +17 -11
- 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 +30 -0
- data/spec/oauth2/access_token_spec.rb +216 -0
- data/spec/oauth2/authenticator_spec.rb +84 -0
- data/spec/oauth2/client_spec.rb +530 -0
- data/spec/oauth2/mac_token_spec.rb +120 -0
- data/spec/oauth2/response_spec.rb +90 -0
- data/spec/oauth2/strategy/assertion_spec.rb +59 -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 +56 -0
- data/spec/oauth2/version_spec.rb +23 -0
- metadata +206 -24
- data/.document +0 -5
- data/CONTRIBUTING.md +0 -18
- data/LICENSE.md +0 -20
- data/oauth2.gemspec +0 -25
data/README.md
CHANGED
@@ -1,30 +1,260 @@
|
|
1
|
-
|
1
|
+
<p align="center">
|
2
|
+
<a href="http://oauth.net/2/" target="_blank" rel="noopener noreferrer">
|
3
|
+
<img src="https://github.com/oauth-xx/oauth2/raw/master/docs/images/logo/oauth2-logo-124px.png?raw=true" alt="OAuth 2.0 Logo by Chris Messina, CC BY-SA 3.0">
|
4
|
+
</a>
|
5
|
+
<a href="https://www.ruby-lang.org/" target="_blank" rel="noopener noreferrer">
|
6
|
+
<img width="124px" src="https://github.com/oauth-xx/oauth2/raw/master/docs/images/logo/ruby-logo-198px.svg?raw=true" alt="Yukihiro Matsumoto, Ruby Visual Identity Team, CC BY-SA 2.5">
|
7
|
+
</a>
|
8
|
+
</p>
|
9
|
+
|
10
|
+
## What
|
11
|
+
|
12
|
+
OAuth 2.0 is the industry-standard protocol for authorization.
|
13
|
+
OAuth 2.0 focuses on client developer simplicity while providing specific authorization flows for web applications,
|
14
|
+
desktop applications, mobile phones, and living room devices.
|
15
|
+
This is a RubyGem for implementing OAuth 2.0 clients and servers in Ruby applications.
|
16
|
+
See the sibling `oauth` gem for OAuth 1.0 implementations in Ruby.
|
17
|
+
|
18
|
+
⚠️ **_WARNING_**: You are viewing the `README` of the soon-to-be-deprecated `1-4-stable`
|
19
|
+
branch which for version 1.4.x releases. Version 2.0 is coming! ⚠️
|
20
|
+
|
21
|
+
---
|
22
|
+
|
23
|
+
* [OAuth 2.0 Spec][oauth2-spec]
|
24
|
+
* [OAuth 1.0 sibling gem][sibling-gem]
|
25
|
+
* Help us finish release [![2.0.0 release milestone][next-milestone-pct-img]][next-milestone-pct] by submitting or reviewing PRs and issues.
|
26
|
+
* Oauth2 gem is _always_ looking for additional maintainers. See [#307][maintainers-discussion].
|
27
|
+
|
28
|
+
[oauth2-spec]: https://oauth.net/2/
|
29
|
+
[sibling-gem]: https://github.com/oauth-xx/oauth-ruby
|
30
|
+
[next-milestone-pct]: https://github.com/oauth-xx/oauth2/milestone/1
|
31
|
+
[next-milestone-pct-img]: https://img.shields.io/github/milestones/progress-percent/oauth-xx/oauth2/1
|
32
|
+
[maintainers-discussion]: https://github.com/oauth-xx/oauth2/issues/307
|
33
|
+
|
34
|
+
## Release Documentation
|
35
|
+
|
36
|
+
<details>
|
37
|
+
<summary>1.4.x Readmes</summary>
|
38
|
+
|
39
|
+
| Version | Release Date | Readme |
|
40
|
+
|---------|--------------|----------------------------------------------------------|
|
41
|
+
| 1.4.8 | Feb 18, 2022 | https://github.com/oauth-xx/oauth2/blob/v1.4.8/README.md |
|
42
|
+
| 1.4.7 | Mar 18, 2021 | https://github.com/oauth-xx/oauth2/blob/v1.4.7/README.md |
|
43
|
+
| 1.4.6 | Mar 18, 2021 | https://github.com/oauth-xx/oauth2/blob/v1.4.6/README.md |
|
44
|
+
| 1.4.5 | Mar 18, 2021 | https://github.com/oauth-xx/oauth2/blob/v1.4.5/README.md |
|
45
|
+
| 1.4.4 | Feb 12, 2020 | https://github.com/oauth-xx/oauth2/blob/v1.4.4/README.md |
|
46
|
+
| 1.4.3 | Jan 29, 2020 | https://github.com/oauth-xx/oauth2/blob/v1.4.3/README.md |
|
47
|
+
| 1.4.2 | Oct 1, 2019 | https://github.com/oauth-xx/oauth2/blob/v1.4.2/README.md |
|
48
|
+
| 1.4.1 | Oct 13, 2018 | https://github.com/oauth-xx/oauth2/blob/v1.4.1/README.md |
|
49
|
+
| 1.4.0 | Jun 9, 2017 | https://github.com/oauth-xx/oauth2/blob/v1.4.0/README.md |
|
50
|
+
</details>
|
51
|
+
|
52
|
+
<details>
|
53
|
+
<summary>1.3.x Readmes</summary>
|
54
|
+
|
55
|
+
| Version | Release Date | Readme |
|
56
|
+
|----------|--------------|----------------------------------------------------------|
|
57
|
+
| 1.3.1 | Mar 3, 2017 | https://github.com/oauth-xx/oauth2/blob/v1.3.1/README.md |
|
58
|
+
| 1.3.0 | Dec 27, 2016 | https://github.com/oauth-xx/oauth2/blob/v1.3.0/README.md |
|
59
|
+
</details>
|
60
|
+
|
61
|
+
<details>
|
62
|
+
<summary>≤= 1.2.x Readmes (2016 and before)</summary>
|
63
|
+
|
64
|
+
| Version | Release Date | Readme |
|
65
|
+
|----------|--------------|----------------------------------------------------------|
|
66
|
+
| 1.2.0 | Jun 30, 2016 | https://github.com/oauth-xx/oauth2/blob/v1.2.0/README.md |
|
67
|
+
| 1.1.0 | Jan 30, 2016 | https://github.com/oauth-xx/oauth2/blob/v1.1.0/README.md |
|
68
|
+
| 1.0.0 | May 23, 2014 | https://github.com/oauth-xx/oauth2/blob/v1.0.0/README.md |
|
69
|
+
| < 1.0.0 | Find here | https://github.com/oauth-xx/oauth2/tags |
|
70
|
+
</details>
|
71
|
+
|
72
|
+
<!--
|
73
|
+
Numbering rows and badges in each row as a visual "database" lookup,
|
74
|
+
as the table is extremely dense, and it can be very difficult to find anything
|
75
|
+
Putting one on each row here, to document the emoji that should be used, and for ease of copy/paste.
|
76
|
+
|
77
|
+
row #s:
|
78
|
+
1️⃣
|
79
|
+
2️⃣
|
80
|
+
3️⃣
|
81
|
+
4️⃣
|
82
|
+
5️⃣
|
83
|
+
6️⃣
|
84
|
+
7️⃣
|
85
|
+
|
86
|
+
badge #s:
|
87
|
+
⛳️
|
88
|
+
🖇
|
89
|
+
🏘
|
90
|
+
🚎
|
91
|
+
🖐
|
92
|
+
🧮
|
93
|
+
📗
|
94
|
+
-->
|
95
|
+
|
96
|
+
| | Project | oauth2 |
|
97
|
+
|:----|-----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
98
|
+
| 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] |
|
99
|
+
| 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-open-img]][🖐prs-open] [![Closed PRs][🧮prs-closed-img]][🧮prs-closed] |
|
100
|
+
| 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] |
|
101
|
+
| 4️⃣ | testing | [![Build][⛳️tot-bld-img]][⛳️tot-bld] [![supported][🖇supported-wf-img]][🖇supported-wf] [![EOL & Code Coverage Build][🏘eol-wf-img]][🏘eol-wf] [![unsupported][🚎unsupported-wf-img]][🚎unsupported-wf] |
|
102
|
+
| 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] |
|
103
|
+
| 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] |
|
104
|
+
| 7️⃣ | spread 💖 | [![Liberapay Patrons][⛳liberapay-img]][⛳liberapay] [![Sponsor Me][🖇sponsor-img]][🖇sponsor] [![Tweet @ Peter][🏘tweet-img]][🏘tweet] [🌏][aboutme] [👼][angelme] [💻][coderme] [🌹][politicme] |
|
105
|
+
|
106
|
+
<!--
|
107
|
+
The link tokens in the following sections should be kept ordered by the row and badge numbering scheme
|
108
|
+
-->
|
109
|
+
|
110
|
+
<!-- 1️⃣ name, license, docs -->
|
111
|
+
[⛳️gem]: https://rubygems.org/gems/oauth2
|
112
|
+
[⛳️name-img]: https://img.shields.io/badge/name-oauth2-brightgreen.svg?style=flat
|
113
|
+
[🖇src-license]: https://opensource.org/licenses/MIT
|
114
|
+
[🖇src-license-img]: https://img.shields.io/badge/License-MIT-green.svg
|
115
|
+
[🏘fossa]: https://app.fossa.io/projects/git%2Bgithub.com%2Foauth-xx%2Foauth2?ref=badge_shield
|
116
|
+
[🏘fossa-img]: https://app.fossa.io/api/projects/git%2Bgithub.com%2Foauth-xx%2Foauth2.svg?type=shield
|
117
|
+
[🚎yard]: https://www.rubydoc.info/github/oauth-xx/oauth2
|
118
|
+
[🚎yard-img]: https://img.shields.io/badge/documentation-rubydoc-brightgreen.svg?style=flat
|
119
|
+
[🖐inch-ci-img]: http://inch-ci.org/github/oauth-xx/oauth2.png
|
120
|
+
|
121
|
+
<!-- 2️⃣ version & activity -->
|
122
|
+
[⛳️version-img]: http://img.shields.io/gem/v/oauth2.svg
|
123
|
+
[🖇DL-total-img]: https://img.shields.io/gem/dt/oauth2.svg
|
124
|
+
[🏘DL-rank-img]: https://img.shields.io/gem/rt/oauth2.svg
|
125
|
+
[🚎src-home]: https://github.com/oauth-xx/oauth2
|
126
|
+
[🚎src-home-img]: https://img.shields.io/badge/source-github-brightgreen.svg?style=flat
|
127
|
+
[🖐prs-open]: https://github.com/oauth-xx/oauth2/pulls
|
128
|
+
[🖐prs-open-img]: https://img.shields.io/github/issues-pr/oauth-xx/oauth2
|
129
|
+
[🧮prs-closed]: https://github.com/oauth-xx/oauth2/pulls?q=is%3Apr+is%3Aclosed
|
130
|
+
[🧮prs-closed-img]: https://img.shields.io/github/issues-pr-closed/oauth-xx/oauth2
|
131
|
+
|
132
|
+
<!-- 3️⃣ maintanence & linting -->
|
133
|
+
[⛳cclim-maint]: https://codeclimate.com/github/oauth-xx/oauth2/maintainability
|
134
|
+
[⛳cclim-maint-img]: https://api.codeclimate.com/v1/badges/688c612528ff90a46955/maintainability
|
135
|
+
[🖇triage-help]: https://www.codetriage.com/oauth-xx/oauth2
|
136
|
+
[🖇triage-help-img]: https://www.codetriage.com/oauth-xx/oauth2/badges/users.svg
|
137
|
+
[🏘depfu]: https://depfu.com/github/oauth-xx/oauth2?project_id=4445
|
138
|
+
[🏘depfu-img]: https://badges.depfu.com/badges/6d34dc1ba682bbdf9ae2a97848241743/count.svg
|
139
|
+
[🚎contributors]: https://github.com/oauth-xx/oauth2/graphs/contributors
|
140
|
+
[🚎contributors-img]: https://img.shields.io/github/contributors-anon/oauth-xx/oauth2
|
141
|
+
[🖐style-wf]: https://github.com/oauth-xx/oauth2/actions/workflows/style.yml
|
142
|
+
[🖐style-wf-img]: https://github.com/oauth-xx/oauth2/actions/workflows/style.yml/badge.svg
|
143
|
+
[🧮kloc]: https://www.youtube.com/watch?v=dQw4w9WgXcQ
|
144
|
+
[🧮kloc-img]: https://img.shields.io/tokei/lines/github.com/oauth-xx/oauth2
|
145
|
+
|
146
|
+
<!-- 4️⃣ testing -->
|
147
|
+
[⛳️tot-bld]: https://actions-badge.atrox.dev/oauth-xx/oauth2/goto
|
148
|
+
[⛳️tot-bld-img]: https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Foauth-xx%2Foauth2%2Fbadge&style=flat
|
149
|
+
[🖇supported-wf]: https://github.com/oauth-xx/oauth2/actions/workflows/supported.yml
|
150
|
+
[🖇supported-wf-img]: https://github.com/oauth-xx/oauth2/actions/workflows/supported.yml/badge.svg
|
151
|
+
[🏘eol-wf]: https://github.com/oauth-xx/oauth2/actions/workflows/coverage.yml
|
152
|
+
[🏘eol-wf-img]: https://github.com/oauth-xx/oauth2/actions/workflows/coverage.yml/badge.svg
|
153
|
+
[🚎unsupported-wf]: https://github.com/oauth-xx/oauth2/actions/workflows/unsupported.yml
|
154
|
+
[🚎unsupported-wf-img]: https://github.com/oauth-xx/oauth2/actions/workflows/unsupported.yml/badge.svg
|
155
|
+
[🖐issues]: https://github.com/oauth-xx/oauth2/issues
|
156
|
+
[🖐issues-img]: https://github.com/oauth-xx/oauth2/issues
|
157
|
+
|
158
|
+
<!-- 5️⃣ coverage & security -->
|
159
|
+
[⛳cclim-cov]: https://codeclimate.com/github/oauth-xx/oauth2/test_coverage
|
160
|
+
[⛳cclim-cov-img]: https://api.codeclimate.com/v1/badges/688c612528ff90a46955/test_coverage
|
161
|
+
[🖇codecov-img]: https://codecov.io/gh/oauth-xx/oauth2/branch/1-4-stable/graph/badge.svg?token=bNqSzNiuo2
|
162
|
+
[🖇codecov]: https://codecov.io/gh/oauth-xx/oauth2
|
163
|
+
[🏘coveralls]: https://coveralls.io/github/oauth-xx/oauth2?branch=1-4-stable
|
164
|
+
[🏘coveralls-img]: https://coveralls.io/repos/github/oauth-xx/oauth2/badge.svg?branch=1-4-stable
|
165
|
+
[🚎sec-pol]: https://github.com/oauth-xx/oauth2/blob/master/SECURITY.md
|
166
|
+
[🚎sec-pol-img]: https://img.shields.io/badge/security-policy-brightgreen.svg?style=flat
|
167
|
+
[🖐codeQL]: https://github.com/oauth-xx/oauth2/security/code-scanning
|
168
|
+
[🖐codeQL-img]: https://github.com/oauth-xx/oauth2/actions/workflows/codeql-analysis.yml/badge.svg
|
169
|
+
|
170
|
+
<!-- 6️⃣ resources -->
|
171
|
+
[⛳gh-discussions]: https://github.com/oauth-xx/oauth2/discussions
|
172
|
+
[⛳gh-discussions-img]: https://img.shields.io/github/discussions/oauth-xx/oauth2
|
173
|
+
[🖇codementor]: https://www.codementor.io/peterboling?utm_source=github&utm_medium=button&utm_term=peterboling&utm_campaign=github
|
174
|
+
[🖇codementor-img]: https://cdn.codementor.io/badges/get_help_github.svg
|
175
|
+
[🏘chat]: https://gitter.im/oauth-xx/oauth2
|
176
|
+
[🏘chat-img]: https://img.shields.io/gitter/room/oauth-xx/oauth2.svg
|
177
|
+
[🚎blog]: http://www.railsbling.com/tags/oauth2/
|
178
|
+
[🚎blog-img]: https://img.shields.io/badge/blog-railsbling-brightgreen.svg?style=flat
|
179
|
+
[🖐wiki]: https://github.com/oauth-xx/oauth2/wiki
|
180
|
+
[🖐wiki-img]: https://img.shields.io/badge/wiki-examples-brightgreen.svg?style=flat
|
181
|
+
|
182
|
+
<!-- 7️⃣ spread 💖 -->
|
183
|
+
[⛳liberapay-img]: https://img.shields.io/liberapay/patrons/pboling.svg?logo=liberapay
|
184
|
+
[⛳liberapay]: https://liberapay.com/pboling/donate
|
185
|
+
[🖇sponsor-img]: https://img.shields.io/badge/sponsor-pboling.svg?style=social&logo=github
|
186
|
+
[🖇sponsor]: https://github.com/sponsors/pboling
|
187
|
+
[🏘tweet-img]: https://img.shields.io/twitter/follow/galtzo.svg?style=social&label=Follow
|
188
|
+
[🏘tweet]: http://twitter.com/galtzo
|
189
|
+
|
190
|
+
<!-- Maintainer Contact Links -->
|
191
|
+
[railsbling]: http://www.railsbling.com
|
192
|
+
[peterboling]: http://www.peterboling.com
|
193
|
+
[aboutme]: https://about.me/peter.boling
|
194
|
+
[angelme]: https://angel.co/peter-boling
|
195
|
+
[coderme]:http://coderwall.com/pboling
|
196
|
+
[politicme]: https://nationalprogressiveparty.org
|
2
197
|
|
3
|
-
[][gem]
|
4
|
-
[][travis]
|
5
|
-
[][gemnasium]
|
6
|
-
[][codeclimate]
|
7
|
-
[][coveralls]
|
8
198
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
199
|
+
## Installation
|
200
|
+
|
201
|
+
```shell
|
202
|
+
gem install oauth2
|
203
|
+
```
|
14
204
|
|
15
|
-
|
205
|
+
Or inside a `Gemfile`
|
16
206
|
|
17
|
-
|
18
|
-
|
207
|
+
```ruby
|
208
|
+
gem 'oauth2'
|
209
|
+
```
|
210
|
+
And then execute in a shell:
|
211
|
+
```shell
|
212
|
+
bundle
|
213
|
+
```
|
214
|
+
|
215
|
+
|
216
|
+
## Compatibility
|
217
|
+
|
218
|
+
Targeted ruby compatibility is non-EOL versions of Ruby, currently 2.7, 3.0 and
|
219
|
+
3.1. Compatibility is further distinguished by supported and unsupported versions of Ruby.
|
220
|
+
Ruby is limited to 1.9+ in the gemspec for the 1.4.x series and will be 2.2+ for 2.x releases (see `master` branch).
|
221
|
+
|
222
|
+
<details>
|
223
|
+
<summary>Ruby Engine Compatibility Policy</summary>
|
224
|
+
|
225
|
+
This gem is tested against MRI, JRuby, and Truffleruby.
|
226
|
+
Each of those has varying versions that target a specific version of MRI Ruby.
|
227
|
+
This gem should work in the just-listed Ruby engines according to the targeted MRI compatibility in the table below.
|
228
|
+
If you would like to add support for additional engines,
|
229
|
+
first make sure Github Actions supports the engine,
|
230
|
+
then submit a PR to the correct maintenance branch as according to the table below.
|
231
|
+
</details>
|
232
|
+
|
233
|
+
<details>
|
234
|
+
<summary>Ruby Version Compatibility Policy</summary>
|
235
|
+
|
236
|
+
If something doesn't work on one of these interpreters, it's a bug.
|
237
|
+
|
238
|
+
This library may inadvertently work (or seem to work) on other Ruby
|
239
|
+
implementations, however support will only be provided for the versions listed
|
240
|
+
above.
|
241
|
+
|
242
|
+
If you would like this library to support another Ruby version, you may
|
243
|
+
volunteer to be a maintainer. Being a maintainer entails making sure all tests
|
244
|
+
run and pass on that implementation. When something breaks on your
|
245
|
+
implementation, you will be responsible for providing patches in a timely
|
246
|
+
fashion. If critical issues for a particular implementation exist at the time
|
247
|
+
of a major release, support for that Ruby version may be dropped.
|
248
|
+
</details>
|
19
249
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
250
|
+
| | Ruby OAuth 2 Version | Maintenance Branch | Supported Officially | Supported Unofficially | Supported Incidentally |
|
251
|
+
|:----|----------------------|--------------------|-------------------------|------------------------|------------------------|
|
252
|
+
| 1️⃣ | 2.0.x (unreleased) | `master` | 2.7, 3.0, 3.1 | 2.6, 2.5 | 2.4, 2.3, 2.2 |
|
253
|
+
| 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 | 2.0, 1.9 |
|
254
|
+
| 3️⃣ | older | N/A | Best of luck to you! | Please upgrade! | |
|
24
255
|
|
25
|
-
|
26
|
-
[
|
27
|
-
[wiki]: https://wiki.github.com/intridea/oauth2
|
256
|
+
NOTE: Once 2.0 is released, the 1.4 series will only receive critical bug and security updates.
|
257
|
+
See [SECURITY.md][🚎sec-pol]
|
28
258
|
|
29
259
|
## Usage Examples
|
30
260
|
|
@@ -36,16 +266,42 @@ client.auth_code.authorize_url(:redirect_uri => 'http://localhost:8080/oauth2/ca
|
|
36
266
|
# => "https://example.org/oauth/authorization?response_type=code&client_id=client_id&redirect_uri=http://localhost:8080/oauth2/callback"
|
37
267
|
|
38
268
|
token = client.auth_code.get_token('authorization_code_value', :redirect_uri => 'http://localhost:8080/oauth2/callback', :headers => {'Authorization' => 'Basic some_password'})
|
39
|
-
response = token.get('/api/resource', :params => {
|
269
|
+
response = token.get('/api/resource', :params => {'query_foo' => 'bar'})
|
40
270
|
response.class.name
|
41
271
|
# => OAuth2::Response
|
42
272
|
```
|
273
|
+
|
274
|
+
<details>
|
275
|
+
<summary>Debugging</summary>
|
276
|
+
|
277
|
+
Set an environment variable, however you would [normally do that](https://github.com/bkeepers/dotenv).
|
278
|
+
|
279
|
+
```ruby
|
280
|
+
# will log both request and response, including bodies
|
281
|
+
ENV['OAUTH_DEBUG'] = 'true'
|
282
|
+
```
|
283
|
+
|
284
|
+
By default, debug output will go to `$stdout`. This can be overridden when
|
285
|
+
initializing your OAuth2::Client.
|
286
|
+
|
287
|
+
```ruby
|
288
|
+
require 'oauth2'
|
289
|
+
client = OAuth2::Client.new(
|
290
|
+
'client_id',
|
291
|
+
'client_secret',
|
292
|
+
:site => 'https://example.org',
|
293
|
+
:logger => Logger.new('example.log', 'weekly')
|
294
|
+
)
|
295
|
+
```
|
296
|
+
</details>
|
297
|
+
|
43
298
|
## OAuth2::Response
|
44
|
-
|
299
|
+
|
300
|
+
The `AccessToken` methods `#get`, `#post`, `#put` and `#delete` and the generic `#request`
|
45
301
|
will return an instance of the #OAuth2::Response class.
|
46
302
|
|
47
|
-
This instance contains a
|
48
|
-
return a Hash if the Content-Type is application/x-www-form-urlencoded or if
|
303
|
+
This instance contains a `#parsed` method that will parse the response body and
|
304
|
+
return a Hash if the `Content-Type` is `application/x-www-form-urlencoded` or if
|
49
305
|
the body is a JSON object. It will return an Array if the body is a JSON
|
50
306
|
array. Otherwise, it will return the original body string.
|
51
307
|
|
@@ -53,26 +309,29 @@ The original response body, headers, and status can be accessed via their
|
|
53
309
|
respective methods.
|
54
310
|
|
55
311
|
## OAuth2::AccessToken
|
312
|
+
|
56
313
|
If you have an existing Access Token for a user, you can initialize an instance
|
57
|
-
using various class methods including the standard new, from_hash (if you have
|
58
|
-
a hash of the values), or from_kvform (if you have an
|
59
|
-
application/x-www-form-urlencoded encoded string of the values).
|
314
|
+
using various class methods including the standard new, `from_hash` (if you have
|
315
|
+
a hash of the values), or `from_kvform` (if you have an
|
316
|
+
`application/x-www-form-urlencoded` encoded string of the values).
|
60
317
|
|
61
318
|
## OAuth2::Error
|
62
|
-
On 400+ status code responses, an OAuth2::Error will be raised. If it is a
|
63
|
-
standard OAuth2 error response, the body will be parsed and #code and #description will contain the values provided from the error and
|
64
|
-
error_description parameters. The #response property of OAuth2::Error will
|
65
|
-
always contain the OAuth2::Response instance.
|
66
319
|
|
67
|
-
|
68
|
-
|
320
|
+
On 400+ status code responses, an `OAuth2::Error` will be raised. If it is a
|
321
|
+
standard OAuth2 error response, the body will be parsed and `#code` and `#description` will contain the values provided from the error and
|
322
|
+
`error_description` parameters. The `#response` property of `OAuth2::Error` will
|
323
|
+
always contain the `OAuth2::Response` instance.
|
324
|
+
|
325
|
+
If you do not want an error to be raised, you may use `:raise_errors => false`
|
326
|
+
option on initialization of the client. In this case the `OAuth2::Response`
|
69
327
|
instance will be returned as usual and on 400+ status code responses, the
|
70
|
-
Response instance will contain the OAuth2::Error instance.
|
328
|
+
Response instance will contain the `OAuth2::Error` instance.
|
71
329
|
|
72
330
|
## Authorization Grants
|
331
|
+
|
73
332
|
Currently the Authorization Code, Implicit, Resource Owner Password Credentials, Client Credentials, and Assertion
|
74
333
|
authentication grant types have helper strategy classes that simplify client
|
75
|
-
use.
|
334
|
+
use. They are available via the `#auth_code`, `#implicit`, `#password`, `#client_credentials`, and `#assertion` methods respectively.
|
76
335
|
|
77
336
|
```ruby
|
78
337
|
auth_url = client.auth_code.authorize_url(:redirect_uri => 'http://localhost:8080/oauth/callback')
|
@@ -96,38 +355,54 @@ request, add a 'headers' hash under 'params':
|
|
96
355
|
token = client.auth_code.get_token('code_value', :redirect_uri => 'http://localhost:8080/oauth/callback', :headers => {'Some' => 'Header'})
|
97
356
|
```
|
98
357
|
|
99
|
-
You can always use the
|
358
|
+
You can always use the `#request` method on the `OAuth2::Client` instance to make
|
100
359
|
requests for tokens for any Authentication grant type.
|
101
360
|
|
102
|
-
##
|
103
|
-
This library aims to support and is [tested against][travis] the following Ruby
|
104
|
-
implementations:
|
361
|
+
## Versioning
|
105
362
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
* [JRuby 9K][jruby]
|
363
|
+
This library aims to adhere to [Semantic Versioning 2.0.0][semver].
|
364
|
+
Violations of this scheme should be reported as bugs. Specifically,
|
365
|
+
if a minor or patch version is released that breaks backward
|
366
|
+
compatibility, a new version should be immediately released that
|
367
|
+
restores compatibility. Breaking changes to the public API will
|
368
|
+
only be introduced with new major versions.
|
113
369
|
|
114
|
-
|
370
|
+
As a result of this policy, you can (and should) specify a
|
371
|
+
dependency on this gem using the [Pessimistic Version Constraint][pvc] with two digits of precision.
|
115
372
|
|
116
|
-
|
373
|
+
For example:
|
117
374
|
|
118
|
-
|
119
|
-
|
120
|
-
|
375
|
+
```ruby
|
376
|
+
spec.add_dependency 'oauth2', '~> 1.4'
|
377
|
+
```
|
121
378
|
|
122
|
-
|
123
|
-
|
124
|
-
run and pass on that implementation. When something breaks on your
|
125
|
-
implementation, you will be responsible for providing patches in a timely
|
126
|
-
fashion. If critical issues for a particular implementation exist at the time
|
127
|
-
of a major release, support for that Ruby version may be dropped.
|
379
|
+
[semver]: http://semver.org/
|
380
|
+
[pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint
|
128
381
|
|
129
382
|
## License
|
130
|
-
Copyright (c) 2011-2013 Michael Bleigh and Intridea, Inc. See [LICENSE][] for
|
131
|
-
details.
|
132
383
|
|
133
|
-
[license]
|
384
|
+
[![License: MIT][🖇src-license-img]][🖇src-license]
|
385
|
+
|
386
|
+
- Copyright (c) 2011-2013 Michael Bleigh and Intridea, Inc.
|
387
|
+
- Copyright (c) 2017-2022 [oauth-xx organization][oauth-xx]
|
388
|
+
- See [LICENSE][license] for details.
|
389
|
+
|
390
|
+
[][fossa2]
|
391
|
+
|
392
|
+
[license]: https://github.com/oauth-xx/oauth2/blob/master/LICENSE
|
393
|
+
[oauth-xx]: https://github.com/oauth-xx
|
394
|
+
[fossa2]: https://app.fossa.io/projects/git%2Bgithub.com%2Foauth-xx%2Foauth2?ref=badge_large
|
395
|
+
|
396
|
+
## Development
|
397
|
+
|
398
|
+
After checking out the repo, run `bundle install` to install dependencies. Then, run `bundle excec rake spec` to run the tests.
|
399
|
+
|
400
|
+
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).
|
401
|
+
|
402
|
+
## Contributing
|
403
|
+
|
404
|
+
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.
|
405
|
+
|
406
|
+
## Code of Conduct
|
407
|
+
|
408
|
+
Everyone interacting in the OAuth2 project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/oauth-xx/oauth2/blob/master/CODE_OF_CONDUCT.md).
|
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)
|