oauth2 1.4.3 → 2.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +188 -16
  3. data/CODE_OF_CONDUCT.md +105 -46
  4. data/CONTRIBUTING.md +27 -1
  5. data/LICENSE +1 -1
  6. data/README.md +428 -131
  7. data/SECURITY.md +26 -0
  8. data/lib/oauth2/access_token.rb +73 -25
  9. data/lib/oauth2/authenticator.rb +12 -5
  10. data/lib/oauth2/client.rb +208 -65
  11. data/lib/oauth2/error.rb +43 -24
  12. data/lib/oauth2/response.rb +81 -22
  13. data/lib/oauth2/strategy/assertion.rb +66 -39
  14. data/lib/oauth2/strategy/auth_code.rb +16 -3
  15. data/lib/oauth2/strategy/base.rb +2 -0
  16. data/lib/oauth2/strategy/client_credentials.rb +4 -2
  17. data/lib/oauth2/strategy/implicit.rb +10 -1
  18. data/lib/oauth2/strategy/password.rb +5 -3
  19. data/lib/oauth2/version.rb +3 -55
  20. data/lib/oauth2.rb +29 -1
  21. metadata +80 -100
  22. data/.document +0 -5
  23. data/.gitignore +0 -19
  24. data/.jrubyrc +0 -1
  25. data/.rspec +0 -2
  26. data/.rubocop.yml +0 -80
  27. data/.rubocop_rspec.yml +0 -26
  28. data/.rubocop_todo.yml +0 -15
  29. data/.ruby-version +0 -1
  30. data/.travis.yml +0 -87
  31. data/Gemfile +0 -40
  32. data/Rakefile +0 -45
  33. data/gemfiles/jruby_1.7.gemfile +0 -11
  34. data/gemfiles/jruby_9.0.gemfile +0 -7
  35. data/gemfiles/jruby_9.1.gemfile +0 -3
  36. data/gemfiles/jruby_9.2.gemfile +0 -3
  37. data/gemfiles/jruby_head.gemfile +0 -3
  38. data/gemfiles/ruby_1.9.gemfile +0 -11
  39. data/gemfiles/ruby_2.0.gemfile +0 -6
  40. data/gemfiles/ruby_2.1.gemfile +0 -6
  41. data/gemfiles/ruby_2.2.gemfile +0 -3
  42. data/gemfiles/ruby_2.3.gemfile +0 -3
  43. data/gemfiles/ruby_2.4.gemfile +0 -3
  44. data/gemfiles/ruby_2.5.gemfile +0 -3
  45. data/gemfiles/ruby_2.6.gemfile +0 -9
  46. data/gemfiles/ruby_2.7.gemfile +0 -9
  47. data/gemfiles/ruby_head.gemfile +0 -9
  48. data/gemfiles/truffleruby.gemfile +0 -3
  49. data/lib/oauth2/mac_token.rb +0 -122
  50. data/oauth2.gemspec +0 -52
data/README.md CHANGED
@@ -1,94 +1,416 @@
1
- # OAuth2
1
+ <p align="center">
2
+ <a href="http://oauth.net/2/" target="_blank" rel="noopener">
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">
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.
2
17
 
3
- If you need the readme for a released version of the gem please find it below:
18
+ ---
19
+
20
+ * [OAuth 2.0 Spec][oauth2-spec]
21
+ * [oauth sibling gem][sibling-gem] for OAuth 1.0 implementations in Ruby.
22
+
23
+ [oauth2-spec]: https://oauth.net/2/
24
+ [sibling-gem]: https://github.com/oauth-xx/oauth-ruby
25
+
26
+ ## Release Documentation
27
+
28
+ ### Version 2.0.x
29
+
30
+ <details>
31
+ <summary>2.0.x Readmes</summary>
32
+
33
+ | Version | Release Date | Readme |
34
+ |---------|--------------|----------------------------------------------------------|
35
+ | 2.0.7 | 2022-08-22 | https://github.com/oauth-xx/oauth2/blob/v2.0.7/README.md |
36
+ | 2.0.6 | 2022-07-13 | https://github.com/oauth-xx/oauth2/blob/v2.0.6/README.md |
37
+ | 2.0.5 | 2022-07-07 | https://github.com/oauth-xx/oauth2/blob/v2.0.5/README.md |
38
+ | 2.0.4 | 2022-07-01 | https://github.com/oauth-xx/oauth2/blob/v2.0.4/README.md |
39
+ | 2.0.3 | 2022-06-28 | https://github.com/oauth-xx/oauth2/blob/v2.0.3/README.md |
40
+ | 2.0.2 | 2022-06-24 | https://github.com/oauth-xx/oauth2/blob/v2.0.2/README.md |
41
+ | 2.0.1 | 2022-06-22 | https://github.com/oauth-xx/oauth2/blob/v2.0.1/README.md |
42
+ | 2.0.0 | 2022-06-21 | https://github.com/oauth-xx/oauth2/blob/v2.0.0/README.md |
43
+ </details>
44
+
45
+ ### Older Releases
46
+
47
+ <details>
48
+ <summary>1.4.x Readmes</summary>
49
+
50
+ | Version | Release Date | Readme |
51
+ |---------|--------------|-----------------------------------------------------------|
52
+ | 1.4.10 | Jul 1, 2022 | https://github.com/oauth-xx/oauth2/blob/v1.4.10/README.md |
53
+ | 1.4.9 | Feb 20, 2022 | https://github.com/oauth-xx/oauth2/blob/v1.4.9/README.md |
54
+ | 1.4.8 | Feb 18, 2022 | https://github.com/oauth-xx/oauth2/blob/v1.4.8/README.md |
55
+ | 1.4.7 | Mar 19, 2021 | https://github.com/oauth-xx/oauth2/blob/v1.4.7/README.md |
56
+ | 1.4.6 | Mar 19, 2021 | https://github.com/oauth-xx/oauth2/blob/v1.4.6/README.md |
57
+ | 1.4.5 | Mar 18, 2021 | https://github.com/oauth-xx/oauth2/blob/v1.4.5/README.md |
58
+ | 1.4.4 | Feb 12, 2020 | https://github.com/oauth-xx/oauth2/blob/v1.4.4/README.md |
59
+ | 1.4.3 | Jan 29, 2020 | https://github.com/oauth-xx/oauth2/blob/v1.4.3/README.md |
60
+ | 1.4.2 | Oct 1, 2019 | https://github.com/oauth-xx/oauth2/blob/v1.4.2/README.md |
61
+ | 1.4.1 | Oct 13, 2018 | https://github.com/oauth-xx/oauth2/blob/v1.4.1/README.md |
62
+ | 1.4.0 | Jun 9, 2017 | https://github.com/oauth-xx/oauth2/blob/v1.4.0/README.md |
63
+ </details>
64
+
65
+ <details>
66
+ <summary>1.3.x Readmes</summary>
4
67
 
5
68
  | Version | Release Date | Readme |
6
69
  |----------|--------------|----------------------------------------------------------|
7
- | 1.4.3 | Jan 29, 2020 | https://github.com/oauth-xx/oauth2/blob/v1.4.3/README.md |
8
- | 1.4.2 | Oct 1, 2019 | https://github.com/oauth-xx/oauth2/blob/v1.4.2/README.md |
9
- | 1.4.1 | Oct 13, 2018 | https://github.com/oauth-xx/oauth2/blob/v1.4.1/README.md |
10
- | 1.4.0 | Jun 9, 2017 | https://github.com/oauth-xx/oauth2/blob/v1.4.0/README.md |
11
70
  | 1.3.1 | Mar 3, 2017 | https://github.com/oauth-xx/oauth2/blob/v1.3.1/README.md |
12
71
  | 1.3.0 | Dec 27, 2016 | https://github.com/oauth-xx/oauth2/blob/v1.3.0/README.md |
72
+ </details>
73
+
74
+ <details>
75
+ <summary>&le;= 1.2.x Readmes (2016 and before)</summary>
76
+
77
+ | Version | Release Date | Readme |
78
+ |----------|--------------|----------------------------------------------------------|
13
79
  | 1.2.0 | Jun 30, 2016 | https://github.com/oauth-xx/oauth2/blob/v1.2.0/README.md |
14
80
  | 1.1.0 | Jan 30, 2016 | https://github.com/oauth-xx/oauth2/blob/v1.1.0/README.md |
15
81
  | 1.0.0 | May 23, 2014 | https://github.com/oauth-xx/oauth2/blob/v1.0.0/README.md |
16
82
  | < 1.0.0 | Find here | https://github.com/oauth-xx/oauth2/tags |
83
+ </details>
84
+
85
+ ## Status
86
+
87
+ <!--
88
+ Numbering rows and badges in each row as a visual "database" lookup,
89
+ as the table is extremely dense, and it can be very difficult to find anything
90
+ Putting one on each row here, to document the emoji that should be used, and for ease of copy/paste.
91
+
92
+ row #s:
93
+ 1️⃣
94
+ 2️⃣
95
+ 3️⃣
96
+ 4️⃣
97
+ 5️⃣
98
+ 6️⃣
99
+ 7️⃣
100
+
101
+ badge #s:
102
+ ⛳️
103
+ 🖇
104
+ 🏘
105
+ 🚎
106
+ 🖐
107
+ 🧮
108
+ 📗
109
+
110
+ appended indicators:
111
+ ♻️ - URL needs to be updated from SASS integration. Find / Replace is insufficient.
112
+ -->
113
+
114
+ | | Project | bundle add oauth2 |
115
+ |:----|-----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
116
+ | 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] |
117
+ | 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♻️] |
118
+ | 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] |
119
+ | 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] |
120
+ | 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] |
121
+ | 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] |
122
+ | 7️⃣ | spread 💖 | [![Liberapay Patrons][⛳liberapay-img]][⛳liberapay] [![Sponsor Me][🖇sponsor-img]][🖇sponsor] [![Tweet @ Peter][🏘tweet-img]][🏘tweet] [🌏][aboutme] [👼][angelme] [💻][coderme] |
123
+
124
+ <!--
125
+ The link tokens in the following sections should be kept ordered by the row and badge numbering scheme
126
+ -->
127
+
128
+ <!-- 1️⃣ name, license, docs -->
129
+ [⛳️gem]: https://rubygems.org/gems/oauth2
130
+ [⛳️name-img]: https://img.shields.io/badge/name-oauth2-brightgreen.svg?style=flat
131
+ [🖇src-license]: https://opensource.org/licenses/MIT
132
+ [🖇src-license-img]: https://img.shields.io/badge/License-MIT-green.svg
133
+ [🏘fossa]: https://app.fossa.io/projects/git%2Bgithub.com%2Foauth-xx%2Foauth2?ref=badge_shield
134
+ [🏘fossa-img]: https://app.fossa.io/api/projects/git%2Bgithub.com%2Foauth-xx%2Foauth2.svg?type=shield
135
+ [🚎yard]: https://www.rubydoc.info/github/oauth-xx/oauth2
136
+ [🚎yard-img]: https://img.shields.io/badge/documentation-rubydoc-brightgreen.svg?style=flat
137
+ [🖐inch-ci-img]: http://inch-ci.org/github/oauth-xx/oauth2.png
138
+
139
+ <!-- 2️⃣ version & activity -->
140
+ [⛳️version-img]: http://img.shields.io/gem/v/oauth2.svg
141
+ [🖇DL-total-img]: https://img.shields.io/gem/dt/oauth2.svg
142
+ [🏘DL-rank-img]: https://img.shields.io/gem/rt/oauth2.svg
143
+ [🚎src-home]: https://github.com/oauth-xx/oauth2
144
+ [🚎src-home-img]: https://img.shields.io/badge/source-github-brightgreen.svg?style=flat
145
+ [🖐prs-o]: https://github.com/oauth-xx/oauth2/pulls
146
+ [🖐prs-o-img]: https://img.shields.io/github/issues-pr/oauth-xx/oauth2
147
+ [🧮prs-c]: https://github.com/oauth-xx/oauth2/pulls?q=is%3Apr+is%3Aclosed
148
+ [🧮prs-c-img]: https://img.shields.io/github/issues-pr-closed/oauth-xx/oauth2
149
+ [📗next♻️]: https://github.com/oauth-xx/oauth2/milestone/2
150
+ [📗next-img♻️]: https://img.shields.io/github/milestones/progress/oauth-xx/oauth2/2?label=Next%20Version
151
+
152
+ <!-- 3️⃣ maintenance & linting -->
153
+ [⛳cclim-maint]: https://codeclimate.com/github/oauth-xx/oauth2/maintainability
154
+ [⛳cclim-maint-img♻️]: https://api.codeclimate.com/v1/badges/688c612528ff90a46955/maintainability
155
+ [🖇triage-help]: https://www.codetriage.com/oauth-xx/oauth2
156
+ [🖇triage-help-img]: https://www.codetriage.com/oauth-xx/oauth2/badges/users.svg
157
+ [🏘depfu♻️]: https://depfu.com/github/oauth-xx/oauth2?project_id=4445
158
+ [🏘depfu-img♻️]: https://badges.depfu.com/badges/6d34dc1ba682bbdf9ae2a97848241743/count.svg
159
+ [🚎contributors]: https://github.com/oauth-xx/oauth2/graphs/contributors
160
+ [🚎contributors-img]: https://img.shields.io/github/contributors-anon/oauth-xx/oauth2
161
+ [🖐style-wf]: https://github.com/oauth-xx/oauth2/actions/workflows/style.yml
162
+ [🖐style-wf-img]: https://github.com/oauth-xx/oauth2/actions/workflows/style.yml/badge.svg
163
+ [🧮kloc]: https://www.youtube.com/watch?v=dQw4w9WgXcQ
164
+ [🧮kloc-img]: https://img.shields.io/tokei/lines/github.com/oauth-xx/oauth2
165
+
166
+ <!-- 4️⃣ testing -->
167
+ [⛳iss-o]: https://github.com/oauth-xx/oauth2/issues
168
+ [⛳iss-o-img]: https://img.shields.io/github/issues-raw/oauth-xx/oauth2
169
+ [🖇iss-c]: https://github.com/oauth-xx/oauth2/issues?q=is%3Aissue+is%3Aclosed
170
+ [🖇iss-c-img]: https://img.shields.io/github/issues-closed-raw/oauth-xx/oauth2
171
+ [🏘sup-wf]: https://github.com/oauth-xx/oauth2/actions/workflows/supported.yml
172
+ [🏘sup-wf-img]: https://github.com/oauth-xx/oauth2/actions/workflows/supported.yml/badge.svg
173
+ [🚎heads-wf]: https://github.com/oauth-xx/oauth2/actions/workflows/heads.yml
174
+ [🚎heads-wf-img]: https://github.com/oauth-xx/oauth2/actions/workflows/heads.yml/badge.svg
175
+ [🖐uns-wf]: https://github.com/oauth-xx/oauth2/actions/workflows/unsupported.yml
176
+ [🖐uns-wf-img]: https://github.com/oauth-xx/oauth2/actions/workflows/unsupported.yml/badge.svg
177
+ [🧮mac-wf]: https://github.com/oauth-xx/oauth2/actions/workflows/macos.yml
178
+ [🧮mac-wf-img]: https://github.com/oauth-xx/oauth2/actions/workflows/macos.yml/badge.svg
179
+ [📗win-wf]: https://github.com/oauth-xx/oauth2/actions/workflows/windows.yml
180
+ [📗win-wf-img]: https://github.com/oauth-xx/oauth2/actions/workflows/windows.yml/badge.svg
181
+
182
+ <!-- 5️⃣ coverage & security -->
183
+ [⛳cclim-cov]: https://codeclimate.com/github/oauth-xx/oauth2/test_coverage
184
+ [⛳cclim-cov-img♻️]: https://api.codeclimate.com/v1/badges/688c612528ff90a46955/test_coverage
185
+ [🖇codecov-img♻️]: https://codecov.io/gh/oauth-xx/oauth2/branch/master/graph/badge.svg?token=bNqSzNiuo2
186
+ [🖇codecov]: https://codecov.io/gh/oauth-xx/oauth2
187
+ [🏘coveralls]: https://coveralls.io/github/oauth-xx/oauth2?branch=master
188
+ [🏘coveralls-img]: https://coveralls.io/repos/github/oauth-xx/oauth2/badge.svg?branch=master
189
+ [🚎sec-pol]: https://github.com/oauth-xx/oauth2/blob/master/SECURITY.md
190
+ [🚎sec-pol-img]: https://img.shields.io/badge/security-policy-brightgreen.svg?style=flat
191
+ [🖐codeQL]: https://github.com/oauth-xx/oauth2/security/code-scanning
192
+ [🖐codeQL-img]: https://github.com/oauth-xx/oauth2/actions/workflows/codeql-analysis.yml/badge.svg
193
+ [🧮cov-wf]: https://github.com/oauth-xx/oauth2/actions/workflows/coverage.yml
194
+ [🧮cov-wf-img]: https://github.com/oauth-xx/oauth2/actions/workflows/coverage.yml/badge.svg
195
+
196
+ <!-- 6️⃣ resources -->
197
+ [⛳gh-discussions]: https://github.com/oauth-xx/oauth2/discussions
198
+ [⛳gh-discussions-img]: https://img.shields.io/github/discussions/oauth-xx/oauth2
199
+ [🖇codementor]: https://www.codementor.io/peterboling?utm_source=github&utm_medium=button&utm_term=peterboling&utm_campaign=github
200
+ [🖇codementor-img]: https://cdn.codementor.io/badges/get_help_github.svg
201
+ [🏘chat]: https://gitter.im/oauth-xx/oauth2
202
+ [🏘chat-img]: https://img.shields.io/gitter/room/oauth-xx/oauth2.svg
203
+ [🚎blog]: http://www.railsbling.com/tags/oauth2/
204
+ [🚎blog-img]: https://img.shields.io/badge/blog-railsbling-brightgreen.svg?style=flat
205
+ [🖐wiki]: https://github.com/oauth-xx/oauth2/wiki
206
+ [🖐wiki-img]: https://img.shields.io/badge/wiki-examples-brightgreen.svg?style=flat
207
+
208
+ <!-- 7️⃣ spread 💖 -->
209
+ [⛳liberapay-img]: https://img.shields.io/liberapay/patrons/pboling.svg?logo=liberapay
210
+ [⛳liberapay]: https://liberapay.com/pboling/donate
211
+ [🖇sponsor-img]: https://img.shields.io/badge/sponsor-pboling.svg?style=social&logo=github
212
+ [🖇sponsor]: https://github.com/sponsors/pboling
213
+ [🏘tweet-img]: https://img.shields.io/twitter/follow/galtzo.svg?style=social&label=Follow
214
+ [🏘tweet]: http://twitter.com/galtzo
215
+
216
+ <!-- Maintainer Contact Links -->
217
+ [railsbling]: http://www.railsbling.com
218
+ [peterboling]: http://www.peterboling.com
219
+ [aboutme]: https://about.me/peter.boling
220
+ [angelme]: https://angel.co/peter-boling
221
+ [coderme]:http://coderwall.com/pboling
17
222
 
18
- [![Gem Version](http://img.shields.io/gem/v/oauth2.svg)][gem]
19
- [![Total Downloads](https://img.shields.io/gem/dt/oauth2.svg)][gem]
20
- [![Downloads Today](https://img.shields.io/gem/rt/oauth2.svg)][gem]
21
- [![Build Status](https://travis-ci.org/oauth-xx/oauth2.svg?branch=1-4-stable)][travis]
22
- [![Test Coverage](https://api.codeclimate.com/v1/badges/688c612528ff90a46955/test_coverage)][codeclimate-coverage]
23
- [![Maintainability](https://api.codeclimate.com/v1/badges/688c612528ff90a46955/maintainability)][codeclimate-maintainability]
24
- [![Depfu](https://badges.depfu.com/badges/6d34dc1ba682bbdf9ae2a97848241743/count.svg)][depfu]
25
- [![Open Source Helpers](https://www.codetriage.com/oauth-xx/oauth2/badges/users.svg)][code-triage]
26
- [![Chat](https://img.shields.io/gitter/room/oauth-xx/oauth2.svg)](https://gitter.im/oauth-xx/oauth2)
27
- [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)][source-license]
28
- [![Documentation](http://inch-ci.org/github/oauth-xx/oauth2.png)][inch-ci]
29
-
30
- [gem]: https://rubygems.org/gems/oauth2
31
- [travis]: http://travis-ci.org/oauth-xx/oauth2
32
- [coveralls]: https://coveralls.io/r/oauth-xx/oauth2
33
- [codeclimate-maintainability]: https://codeclimate.com/github/oauth-xx/oauth2/maintainability
34
- [codeclimate-coverage]: https://codeclimate.com/github/oauth-xx/oauth2/test_coverage
35
- [depfu]: https://depfu.com/github/oauth-xx/oauth2
36
- [source-license]: https://opensource.org/licenses/MIT
37
- [inch-ci]: http://inch-ci.org/github/oauth-xx/oauth2
38
- [code-triage]: https://www.codetriage.com/oauth-xx/oauth2
39
- [fossa1]: https://app.fossa.io/projects/git%2Bgithub.com%2Foauth-xx%2Foauth2?ref=badge_shield
40
-
41
- A Ruby wrapper for the [OAuth 2.0 specification][oauth2-spec].
223
+ ## Installation
42
224
 
43
- [oauth2-spec]: https://oauth.net/2/
225
+ Install the gem and add to the application's Gemfile by executing:
44
226
 
45
- ## Installation
227
+ $ bundle add oauth2
46
228
 
47
- Add this line to your application's Gemfile:
229
+ If bundler is not being used to manage dependencies, install the gem by executing:
48
230
 
49
- ```ruby
50
- gem 'oauth2'
51
- ```
231
+ $ gem install oauth2
52
232
 
53
- And then execute:
233
+ ## OAuth2 for Enterprise
54
234
 
55
- $ bundle
235
+ Available as part of the Tidelift Subscription.
56
236
 
57
- Or install it yourself as:
237
+ The maintainers of OAuth2 and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use. [Learn more.][tidelift-ref]
58
238
 
59
- $ gem install oauth2
239
+ [tidelift-ref]: https://tidelift.com/subscription/pkg/rubygems-oauth2?utm_source=rubygems-oauth2&utm_medium=referral&utm_campaign=enterprise
240
+
241
+ ## Security contact information
242
+
243
+ To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security).
244
+ Tidelift will coordinate the fix and disclosure.
245
+
246
+ For more see [SECURITY.md][🚎sec-pol].
247
+
248
+ ## What is new for v2.0?
60
249
 
61
- ## Resources
250
+ - Officially support Ruby versions >= 2.7
251
+ - Unofficially support Ruby versions >= 2.5
252
+ - Incidentally support Ruby versions >= 2.2
253
+ - Drop support for the expired MAC Draft (all versions)
254
+ - Support IETF rfc7523 JWT Bearer Tokens
255
+ - Support IETF rfc7231 Relative Location in Redirect
256
+ - Support IETF rfc6749 Don't set oauth params when nil
257
+ - 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)
258
+ - Support new formats, including from [jsonapi.org](http://jsonapi.org/format/): `application/vdn.api+json`, `application/vnd.collection+json`, `application/hal+json`, `application/problem+json`
259
+ - Adds new option to `OAuth2::Client#get_token`:
260
+ - `:access_token_class` (`AccessToken`); user specified class to use for all calls to `get_token`
261
+ - Adds new option to `OAuth2::AccessToken#initialize`:
262
+ - `:expires_latency` (`nil`); number of seconds by which AccessToken validity will be reduced to offset latency
263
+ - By default, keys are transformed to camel case.
264
+ - Original keys will still work as previously, in most scenarios, thanks to `rash_alt` gem.
265
+ - However, this is a _breaking_ change if you rely on `response.parsed.to_h`, as the keys in the result will be camel case.
266
+ - As of version 2.0.4 you can turn key transformation off with the `snaky: false` option.
267
+ - By default, the `:auth_scheme` is now `:basic_auth` (instead of `:request_body`)
268
+ - Third-party strategies and gems may need to be updated if a provider was requiring client id/secret in the request body
269
+ - [... A lot more](https://github.com/oauth-xx/oauth2/blob/master/CHANGELOG.md#2.0.0)
62
270
 
63
- * [View Source on GitHub][code]
64
- * [Report Issues on GitHub][issues]
65
- * [Read More at the Wiki][wiki]
271
+ ## Compatibility
66
272
 
67
- [code]: https://github.com/oauth-xx/oauth2
68
- [issues]: https://github.com/oauth-xx/oauth2/issues
69
- [wiki]: https://wiki.github.com/oauth-xx/oauth2
273
+ Targeted ruby compatibility is non-EOL versions of Ruby, currently 2.7, 3.0 and
274
+ 3.1. Compatibility is further distinguished by supported and unsupported versions of Ruby.
275
+ Ruby is limited to 2.2+ for 2.x releases. See `1-4-stable` branch for older rubies.
276
+
277
+ <details>
278
+ <summary>Ruby Engine Compatibility Policy</summary>
279
+
280
+ This gem is tested against MRI, JRuby, and Truffleruby.
281
+ Each of those has varying versions that target a specific version of MRI Ruby.
282
+ This gem should work in the just-listed Ruby engines according to the targeted MRI compatibility in the table below.
283
+ If you would like to add support for additional engines,
284
+ first make sure Github Actions supports the engine,
285
+ then submit a PR to the correct maintenance branch as according to the table below.
286
+ </details>
287
+
288
+ <details>
289
+ <summary>Ruby Version Compatibility Policy</summary>
290
+
291
+ If something doesn't work on one of these interpreters, it's a bug.
292
+
293
+ This library may inadvertently work (or seem to work) on other Ruby
294
+ implementations, however support will only be provided for the versions listed
295
+ above.
296
+
297
+ If you would like this library to support another Ruby version, you may
298
+ volunteer to be a maintainer. Being a maintainer entails making sure all tests
299
+ run and pass on that implementation. When something breaks on your
300
+ implementation, you will be responsible for providing patches in a timely
301
+ fashion. If critical issues for a particular implementation exist at the time
302
+ of a major release, support for that Ruby version may be dropped.
303
+ </details>
304
+
305
+ | | Ruby OAuth2 Version | Maintenance Branch | Supported Officially | Supported Unofficially | Supported Incidentally |
306
+ |:----|---------------------|--------------------|-------------------------|------------------------|------------------------|
307
+ | 1️⃣ | 2.0.x | `master` | 2.7, 3.0, 3.1 | 2.5, 2.6 | 2.2, 2.3, 2.4 |
308
+ | 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 |
309
+ | 3️⃣ | older | N/A | Best of luck to you! | Please upgrade! | |
310
+
311
+ NOTE: The 1.4 series will only receive critical security updates.
312
+ See [SECURITY.md][🚎sec-pol]
70
313
 
71
314
  ## Usage Examples
72
315
 
316
+ ### `authorize_url` and `token_url` are on site root (Just Works!)
317
+
73
318
  ```ruby
74
319
  require 'oauth2'
75
- client = OAuth2::Client.new('client_id', 'client_secret', :site => 'https://example.org')
76
-
77
- client.auth_code.authorize_url(:redirect_uri => 'http://localhost:8080/oauth2/callback')
78
- # => "https://example.org/oauth/authorization?response_type=code&client_id=client_id&redirect_uri=http://localhost:8080/oauth2/callback"
320
+ client = OAuth2::Client.new('client_id', 'client_secret', site: 'https://example.org')
321
+ # => #<OAuth2::Client:0x00000001204c8288 @id="client_id", @secret="client_sec...
322
+ client.auth_code.authorize_url(redirect_uri: 'http://localhost:8080/oauth2/callback')
323
+ # => "https://example.org/oauth/authorize?client_id=client_id&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Foauth2%2Fcallback&response_type=code"
79
324
 
80
- token = client.auth_code.get_token('authorization_code_value', :redirect_uri => 'http://localhost:8080/oauth2/callback', :headers => {'Authorization' => 'Basic some_password'})
81
- response = token.get('/api/resource', :params => { 'query_foo' => 'bar' })
325
+ access = client.auth_code.get_token('authorization_code_value', redirect_uri: 'http://localhost:8080/oauth2/callback', headers: {'Authorization' => 'Basic some_password'})
326
+ response = access.get('/api/resource', params: {'query_foo' => 'bar'})
82
327
  response.class.name
83
328
  # => OAuth2::Response
84
329
  ```
330
+
331
+ ### Relative `authorize_url` and `token_url` (Not on site root, Just Works!)
332
+
333
+ In above example, the default Authorization URL is `oauth/authorize` and default Access Token URL is `oauth/token`, and, as they are missing a leading `/`, both are relative.
334
+
335
+ ```ruby
336
+ client = OAuth2::Client.new('client_id', 'client_secret', site: 'https://example.org/nested/directory/on/your/server')
337
+ # => #<OAuth2::Client:0x00000001204c8288 @id="client_id", @secret="client_sec...
338
+ client.auth_code.authorize_url(redirect_uri: 'http://localhost:8080/oauth2/callback')
339
+ # => "https://example.org/nested/directory/on/your/server/oauth/authorize?client_id=client_id&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Foauth2%2Fcallback&response_type=code"
340
+ ```
341
+
342
+ ### Customize `authorize_url` and `token_url`
343
+
344
+ You can specify custom URLs for authorization and access token, and when using a leading `/` they will _not be relative_, as shown below:
345
+
346
+ ```ruby
347
+ client = OAuth2::Client.new('client_id', 'client_secret',
348
+ site: 'https://example.org/nested/directory/on/your/server',
349
+ authorize_url: '/jaunty/authorize/',
350
+ token_url: '/stirrups/access_token')
351
+ # => #<OAuth2::Client:0x00000001204c8288 @id="client_id", @secret="client_sec...
352
+ client.auth_code.authorize_url(redirect_uri: 'http://localhost:8080/oauth2/callback')
353
+ # => "https://example.org/jaunty/authorize/?client_id=client_id&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Foauth2%2Fcallback&response_type=code"
354
+ client.class.name
355
+ # => OAuth2::Client
356
+ ```
357
+
358
+ ### snake_case and indifferent access in Response#parsed
359
+
360
+ ```ruby
361
+ response = access.get('/api/resource', params: {'query_foo' => 'bar'})
362
+ # Even if the actual response is CamelCase. it will be made available as snaky:
363
+ JSON.parse(response.body) # => {"accessToken"=>"aaaaaaaa", "additionalData"=>"additional"}
364
+ response.parsed # => {"access_token"=>"aaaaaaaa", "additional_data"=>"additional"}
365
+ response.parsed.access_token # => "aaaaaaaa"
366
+ response.parsed[:access_token] # => "aaaaaaaa"
367
+ response.parsed.additional_data # => "additional"
368
+ response.parsed[:additional_data] # => "additional"
369
+ response.parsed.class.name # => OAuth2::SnakyHash (subclass of Hashie::Mash::Rash, from `rash_alt` gem)
370
+ ```
371
+
372
+ #### What if I hate snakes and/or indifference?
373
+
374
+ ```ruby
375
+ response = access.get('/api/resource', params: {'query_foo' => 'bar'}, snaky: false)
376
+ JSON.parse(response.body) # => {"accessToken"=>"aaaaaaaa", "additionalData"=>"additional"}
377
+ response.parsed # => {"accessToken"=>"aaaaaaaa", "additionalData"=>"additional"}
378
+ response.parsed['accessToken'] # => "aaaaaaaa"
379
+ response.parsed['additionalData'] # => "additional"
380
+ response.parsed.class.name # => Hash (just, regular old Hash)
381
+ ```
382
+
383
+ <details>
384
+ <summary>Debugging</summary>
385
+
386
+ Set an environment variable, however you would [normally do that](https://github.com/bkeepers/dotenv).
387
+
388
+ ```ruby
389
+ # will log both request and response, including bodies
390
+ ENV['OAUTH_DEBUG'] = 'true'
391
+ ```
392
+
393
+ By default, debug output will go to `$stdout`. This can be overridden when
394
+ initializing your OAuth2::Client.
395
+
396
+ ```ruby
397
+ require 'oauth2'
398
+ client = OAuth2::Client.new(
399
+ 'client_id',
400
+ 'client_secret',
401
+ site: 'https://example.org',
402
+ logger: Logger.new('example.log', 'weekly')
403
+ )
404
+ ```
405
+ </details>
406
+
85
407
  ## OAuth2::Response
86
408
 
87
- The AccessToken methods #get, #post, #put and #delete and the generic #request
409
+ The `AccessToken` methods `#get`, `#post`, `#put` and `#delete` and the generic `#request`
88
410
  will return an instance of the #OAuth2::Response class.
89
411
 
90
- This instance contains a #parsed method that will parse the response body and
91
- return a Hash if the Content-Type is application/x-www-form-urlencoded or if
412
+ This instance contains a `#parsed` method that will parse the response body and
413
+ return a Hash-like [`OAuth2::SnakyHash`](https://github.com/oauth-xx/oauth2/blob/master/lib/oauth2/snaky_hash.rb) if the `Content-Type` is `application/x-www-form-urlencoded` or if
92
414
  the body is a JSON object. It will return an Array if the body is a JSON
93
415
  array. Otherwise, it will return the original body string.
94
416
 
@@ -98,100 +420,67 @@ respective methods.
98
420
  ## OAuth2::AccessToken
99
421
 
100
422
  If you have an existing Access Token for a user, you can initialize an instance
101
- using various class methods including the standard new, from_hash (if you have
102
- a hash of the values), or from_kvform (if you have an
103
- application/x-www-form-urlencoded encoded string of the values).
423
+ using various class methods including the standard new, `from_hash` (if you have
424
+ a hash of the values), or `from_kvform` (if you have an
425
+ `application/x-www-form-urlencoded` encoded string of the values).
104
426
 
105
427
  ## OAuth2::Error
106
428
 
107
- On 400+ status code responses, an OAuth2::Error will be raised. If it is a
108
- standard OAuth2 error response, the body will be parsed and #code and #description will contain the values provided from the error and
109
- error_description parameters. The #response property of OAuth2::Error will
110
- always contain the OAuth2::Response instance.
429
+ On 400+ status code responses, an `OAuth2::Error` will be raised. If it is a
430
+ standard OAuth2 error response, the body will be parsed and `#code` and `#description` will contain the values provided from the error and
431
+ `error_description` parameters. The `#response` property of `OAuth2::Error` will
432
+ always contain the `OAuth2::Response` instance.
111
433
 
112
- If you do not want an error to be raised, you may use :raise_errors => false
113
- option on initialization of the client. In this case the OAuth2::Response
434
+ If you do not want an error to be raised, you may use `:raise_errors => false`
435
+ option on initialization of the client. In this case the `OAuth2::Response`
114
436
  instance will be returned as usual and on 400+ status code responses, the
115
- Response instance will contain the OAuth2::Error instance.
437
+ Response instance will contain the `OAuth2::Error` instance.
116
438
 
117
439
  ## Authorization Grants
118
440
 
119
441
  Currently the Authorization Code, Implicit, Resource Owner Password Credentials, Client Credentials, and Assertion
120
442
  authentication grant types have helper strategy classes that simplify client
121
- use. They are available via the #auth_code, #implicit, #password, #client_credentials, and #assertion methods respectively.
443
+ 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.
122
444
 
445
+ These aren't full examples, but demonstrative of the differences between usage for each strategy.
123
446
  ```ruby
124
- auth_url = client.auth_code.authorize_url(:redirect_uri => 'http://localhost:8080/oauth/callback')
125
- token = client.auth_code.get_token('code_value', :redirect_uri => 'http://localhost:8080/oauth/callback')
447
+ auth_url = client.auth_code.authorize_url(redirect_uri: 'http://localhost:8080/oauth/callback')
448
+ access = client.auth_code.get_token('code_value', redirect_uri: 'http://localhost:8080/oauth/callback')
126
449
 
127
- auth_url = client.implicit.authorize_url(:redirect_uri => 'http://localhost:8080/oauth/callback')
450
+ auth_url = client.implicit.authorize_url(redirect_uri: 'http://localhost:8080/oauth/callback')
128
451
  # get the token params in the callback and
129
- token = OAuth2::AccessToken.from_kvform(client, query_string)
130
-
131
- token = client.password.get_token('username', 'password')
132
-
133
- token = client.client_credentials.get_token
134
-
135
- token = client.assertion.get_token(assertion_params)
452
+ access = OAuth2::AccessToken.from_kvform(client, query_string)
453
+
454
+ access = client.password.get_token('username', 'password')
455
+
456
+ access = client.client_credentials.get_token
457
+
458
+ # Client Assertion Strategy
459
+ # see: https://tools.ietf.org/html/rfc7523
460
+ claimset = {
461
+ iss: 'http://localhost:3001',
462
+ aud: 'http://localhost:8080/oauth2/token',
463
+ sub: 'me@example.com',
464
+ exp: Time.now.utc.to_i + 3600,
465
+ }
466
+ assertion_params = [claimset, 'HS256', 'secret_key']
467
+ access = client.assertion.get_token(assertion_params)
468
+
469
+ # The `access` (i.e. access token) is then used like so:
470
+ access.token # actual access_token string, if you need it somewhere
471
+ access.get('/api/stuff') # making api calls with access token
136
472
  ```
137
473
 
138
474
  If you want to specify additional headers to be sent out with the
139
475
  request, add a 'headers' hash under 'params':
140
476
 
141
477
  ```ruby
142
- token = client.auth_code.get_token('code_value', :redirect_uri => 'http://localhost:8080/oauth/callback', :headers => {'Some' => 'Header'})
478
+ access = client.auth_code.get_token('code_value', redirect_uri: 'http://localhost:8080/oauth/callback', headers: {'Some' => 'Header'})
143
479
  ```
144
480
 
145
- You can always use the #request method on the OAuth2::Client instance to make
481
+ You can always use the `#request` method on the `OAuth2::Client` instance to make
146
482
  requests for tokens for any Authentication grant type.
147
483
 
148
- ## Supported Ruby Versions
149
-
150
- This library aims to support and is [tested against][travis] the following Ruby
151
- implementations:
152
-
153
- ### Rubies with support ending at Oauth2 1.x
154
-
155
- * Ruby 1.9.3
156
- - [JRuby 1.7][jruby-1.7] (targets MRI v1.9)
157
-
158
- * Ruby 2.0.0
159
- - [JRuby 9.0][jruby-9.0] (targets MRI v2.0)
160
- * Ruby 2.1
161
-
162
- ---
163
-
164
- ### Rubies with continued support past Oauth2 2.x
165
-
166
- * Ruby 2.2 - Support ends with version 2.x series
167
- * Ruby 2.3 - Support ends with version 3.x series
168
- - [JRuby 9.1][jruby-9.1] (targets MRI v2.3)
169
- * Ruby 2.4 - Support ends with version 4.x series
170
- * Ruby 2.5 - Support ends with version 5.x series
171
- - [JRuby 9.2][jruby-9.2] (targets MRI v2.5)
172
- - [truffleruby][truffleruby] (targets MRI 2.5)
173
- * Ruby 2.6 - Support ends with version 6.x series
174
- * Ruby 2.7 - Support ends with version 7.x series
175
-
176
- [jruby-1.7]: https://www.jruby.org/2017/05/11/jruby-1-7-27.html
177
- [jruby-9.0]: https://www.jruby.org/2016/01/26/jruby-9-0-5-0.html
178
- [jruby-9.1]: https://www.jruby.org/2017/05/16/jruby-9-1-9-0.html
179
- [jruby-9.2]: https://www.jruby.org/2018/05/24/jruby-9-2-0-0.html
180
- [truffleruby]: https://github.com/oracle/truffleruby
181
-
182
- If something doesn't work on one of these interpreters, it's a bug.
183
-
184
- This library may inadvertently work (or seem to work) on other Ruby
185
- implementations, however support will only be provided for the versions listed
186
- above.
187
-
188
- If you would like this library to support another Ruby version, you may
189
- volunteer to be a maintainer. Being a maintainer entails making sure all tests
190
- run and pass on that implementation. When something breaks on your
191
- implementation, you will be responsible for providing patches in a timely
192
- fashion. If critical issues for a particular implementation exist at the time
193
- of a major release, support for that Ruby version may be dropped.
194
-
195
484
  ## Versioning
196
485
 
197
486
  This library aims to adhere to [Semantic Versioning 2.0.0][semver].
@@ -207,7 +496,7 @@ dependency on this gem using the [Pessimistic Version Constraint][pvc] with two
207
496
  For example:
208
497
 
209
498
  ```ruby
210
- spec.add_dependency 'oauth2', '~> 1.4'
499
+ spec.add_dependency 'oauth2', '~> 2.0'
211
500
  ```
212
501
 
213
502
  [semver]: http://semver.org/
@@ -215,15 +504,15 @@ spec.add_dependency 'oauth2', '~> 1.4'
215
504
 
216
505
  ## License
217
506
 
218
- [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)][source-license]
507
+ [![License: MIT][🖇src-license-img]][🖇src-license]
219
508
 
220
509
  - Copyright (c) 2011-2013 Michael Bleigh and Intridea, Inc.
221
- - Copyright (c) 2017-2018 [oauth-xx organization][oauth-xx]
510
+ - Copyright (c) 2017-2022 [oauth-xx organization][oauth-xx]
222
511
  - See [LICENSE][license] for details.
223
512
 
224
513
  [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Foauth-xx%2Foauth2.svg?type=large)][fossa2]
225
514
 
226
- [license]: LICENSE
515
+ [license]: https://github.com/oauth-xx/oauth2/blob/master/LICENSE
227
516
  [oauth-xx]: https://github.com/oauth-xx
228
517
  [fossa2]: https://app.fossa.io/projects/git%2Bgithub.com%2Foauth-xx%2Foauth2?ref=badge_large
229
518
 
@@ -235,7 +524,15 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
235
524
 
236
525
  ## Contributing
237
526
 
238
- 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.
527
+ See [CONTRIBUTING.md][contributing]
528
+
529
+ [contributing]: https://github.com/oauth-xx/oauth2/blob/master/CONTRIBUTING.md
530
+
531
+ ## Contributors
532
+
533
+ [![Contributors](https://contrib.rocks/image?repo=oauth-xx/oauth2)]("https://github.com/oauth-xx/oauth2/graphs/contributors")
534
+
535
+ Made with [contributors-img](https://contrib.rocks).
239
536
 
240
537
  ## Code of Conduct
241
538