oauth2 1.4.3 → 2.0.7

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