oauth 0.5.6 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +478 -0
  3. data/CODE_OF_CONDUCT.md +84 -0
  4. data/CONTRIBUTING.md +23 -0
  5. data/LICENSE +18 -17
  6. data/README.md +383 -0
  7. data/SECURITY.md +20 -0
  8. data/bin/oauth +10 -6
  9. data/lib/oauth/cli/authorize_command.rb +57 -55
  10. data/lib/oauth/cli/base_command.rb +163 -157
  11. data/lib/oauth/cli/help_command.rb +9 -5
  12. data/lib/oauth/cli/query_command.rb +26 -17
  13. data/lib/oauth/cli/sign_command.rb +58 -55
  14. data/lib/oauth/cli/version_command.rb +8 -4
  15. data/lib/oauth/cli.rb +21 -19
  16. data/lib/oauth/client/action_controller_request.rb +23 -21
  17. data/lib/oauth/client/em_http.rb +101 -99
  18. data/lib/oauth/client/helper.rb +83 -82
  19. data/lib/oauth/client/net_http.rb +112 -105
  20. data/lib/oauth/client.rb +2 -0
  21. data/lib/oauth/consumer.rb +157 -135
  22. data/lib/oauth/errors/error.rb +2 -0
  23. data/lib/oauth/errors/problem.rb +3 -0
  24. data/lib/oauth/errors/unauthorized.rb +7 -1
  25. data/lib/oauth/errors.rb +5 -3
  26. data/lib/oauth/helper.rb +26 -18
  27. data/lib/oauth/oauth.rb +6 -4
  28. data/lib/oauth/oauth_test_helper.rb +6 -4
  29. data/lib/oauth/request_proxy/action_controller_request.rb +56 -57
  30. data/lib/oauth/request_proxy/action_dispatch_request.rb +8 -4
  31. data/lib/oauth/request_proxy/base.rb +136 -132
  32. data/lib/oauth/request_proxy/curb_request.rb +49 -43
  33. data/lib/oauth/request_proxy/em_http_request.rb +59 -49
  34. data/lib/oauth/request_proxy/jabber_request.rb +12 -9
  35. data/lib/oauth/request_proxy/mock_request.rb +5 -3
  36. data/lib/oauth/request_proxy/net_http.rb +63 -54
  37. data/lib/oauth/request_proxy/rack_request.rb +35 -31
  38. data/lib/oauth/request_proxy/rest_client_request.rb +54 -50
  39. data/lib/oauth/request_proxy/typhoeus_request.rb +51 -45
  40. data/lib/oauth/request_proxy.rb +7 -4
  41. data/lib/oauth/server.rb +14 -12
  42. data/lib/oauth/signature/base.rb +80 -71
  43. data/lib/oauth/signature/hmac/sha1.rb +16 -10
  44. data/lib/oauth/signature/hmac/sha256.rb +16 -10
  45. data/lib/oauth/signature/plaintext.rb +18 -20
  46. data/lib/oauth/signature/rsa/sha1.rb +46 -38
  47. data/lib/oauth/signature.rb +8 -5
  48. data/lib/oauth/token.rb +7 -5
  49. data/lib/oauth/tokens/access_token.rb +5 -3
  50. data/lib/oauth/tokens/consumer_token.rb +4 -2
  51. data/lib/oauth/tokens/request_token.rb +12 -10
  52. data/lib/oauth/tokens/server_token.rb +2 -1
  53. data/lib/oauth/tokens/token.rb +2 -0
  54. data/lib/oauth/version.rb +5 -1
  55. data/lib/oauth.rb +17 -9
  56. metadata +94 -98
  57. data/README.rdoc +0 -88
data/README.md ADDED
@@ -0,0 +1,383 @@
1
+ <p align="center">
2
+ <a href="http://oauth.net/core/1.0/" target="_blank" rel="noopener">
3
+ <img width="124px" src="https://github.com/oauth-xx/oauth-ruby/raw/main/docs/images/logo/Oauth_logo.svg?raw=true" alt="OAuth 1.0 Logo by Chris Messina, CC BY-SA 3.0, via Wikimedia Commons">
4
+ </a>
5
+ <a href="https://www.ruby-lang.org/" target="_blank" rel="noopener">
6
+ <img width="124px" src="https://github.com/oauth-xx/oauth-ruby/raw/main/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
+ # Ruby OAuth
11
+
12
+ OAuth 1.0 is an industry-standard protocol for authorization.
13
+
14
+ This is a RubyGem for implementing both OAuth 1.0 clients and servers in Ruby applications.
15
+ See the sibling `oauth2` gem for OAuth 2.0 implementations in Ruby.
16
+
17
+ * [OAuth 1.0 Spec][oauth1-spec]
18
+ * [oauth2 sibling gem][sibling-gem] for OAuth 2.0 implementations in Ruby.
19
+
20
+ [oauth1-spec]: http://oauth.net/core/1.0/
21
+ [sibling-gem]: https://github.com/oauth-xx/oauth-ruby
22
+
23
+ **NOTE**
24
+
25
+ This README, on branch `v0.6-maintenance`, targets 0.6.x series releases.
26
+ The v0.6.x series of releases will be EOL no later than April, 2024.
27
+ For later releases please see the `main` branch README.
28
+
29
+ ## Status
30
+
31
+ <!--
32
+ Numbering rows and badges in each row as a visual "database" lookup,
33
+ as the table is extremely dense, and it can be very difficult to find anything
34
+ Putting one on each row here, to document the emoji that should be used, and for ease of copy/paste.
35
+
36
+ row #s:
37
+ 1️⃣
38
+ 2️⃣
39
+ 3️⃣
40
+ 4️⃣
41
+ 5️⃣
42
+ 6️⃣
43
+ 7️⃣
44
+
45
+ badge #s:
46
+ ⛳️
47
+ 🖇
48
+ 🏘
49
+ 🚎
50
+ 🖐
51
+ 🧮
52
+ 📗
53
+
54
+ appended indicators:
55
+ ♻️ - URL needs to be updated from SASS integration. Find / Replace is insufficient.
56
+ -->
57
+
58
+ | | Project | bundle add oauth |
59
+ |:----|-----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
60
+ | 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] |
61
+ | 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]--> |
62
+ | 3️⃣ | maintenance & 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] |
63
+ | 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] |
64
+ | 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] |
65
+ | 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] |
66
+ | 7️⃣ | spread 💖 | [![Liberapay Patrons][⛳liberapay-img]][⛳liberapay] [![Sponsor Me][🖇sponsor-img]][🖇sponsor] [![Tweet @ Peter][🏘tweet-img]][🏘tweet] [🌏][aboutme] [👼][angelme] [💻][coderme] |
67
+
68
+ <!--
69
+ The link tokens in the following sections should be kept ordered by the row and badge numbering scheme
70
+ -->
71
+
72
+ <!-- 1️⃣ name, license, docs -->
73
+ [⛳️gem]: https://rubygems.org/gems/oauth
74
+ [⛳️name-img]: https://img.shields.io/badge/name-oauth-brightgreen.svg?style=flat
75
+ [🖇src-license]: https://opensource.org/licenses/MIT
76
+ [🖇src-license-img]: https://img.shields.io/badge/License-MIT-green.svg
77
+ [🏘fossa]: https://app.fossa.io/projects/git%2Bgithub.com%2Foauth-xx%2Foauth-ruby?ref=badge_shield
78
+ [🏘fossa-img]: https://app.fossa.io/api/projects/git%2Bgithub.com%2Foauth-xx%2Foauth-ruby.svg?type=shield
79
+ [🚎yard]: https://www.rubydoc.info/github/oauth-xx/oauth-ruby
80
+ [🚎yard-img]: https://img.shields.io/badge/documentation-rubydoc-brightgreen.svg?style=flat
81
+ [🖐inch-ci-img]: http://inch-ci.org/github/oauth-xx/oauth-ruby.png
82
+
83
+ <!-- 2️⃣ version & activity -->
84
+ [⛳️version-img]: http://img.shields.io/gem/v/oauth.svg
85
+ [🖇DL-total-img]: https://img.shields.io/gem/dt/oauth.svg
86
+ [🏘DL-rank-img]: https://img.shields.io/gem/rt/oauth.svg
87
+ [🚎src-home]: https://github.com/oauth-xx/oauth-ruby
88
+ [🚎src-home-img]: https://img.shields.io/badge/source-github-brightgreen.svg?style=flat
89
+ [🖐prs-o]: https://github.com/oauth-xx/oauth-ruby/pulls
90
+ [🖐prs-o-img]: https://img.shields.io/github/issues-pr/oauth-xx/oauth-ruby
91
+ [🧮prs-c]: https://github.com/oauth-xx/oauth-ruby/pulls?q=is%3Apr+is%3Aclosed
92
+ [🧮prs-c-img]: https://img.shields.io/github/issues-pr-closed/oauth-xx/oauth-ruby
93
+ [📗next]: https://github.com/oauth-xx/oauth-ruby/milestone/1
94
+ [📗next-img]: https://img.shields.io/github/milestones/progress/oauth-xx/oauth-ruby/1?label=Next%20Version
95
+
96
+ <!-- 3️⃣ maintanence & linting -->
97
+ [⛳cclim-maint]: https://codeclimate.com/github/oauth-xx/oauth-ruby/maintainability
98
+ [⛳cclim-maint-img♻️]: https://api.codeclimate.com/v1/badges/3cf23270c21e8791d788/maintainability
99
+ [🖇triage-help]: https://www.codetriage.com/oauth-xx/oauth-ruby
100
+ [🖇triage-help-img]: https://www.codetriage.com/oauth-xx/oauth-ruby/badges/users.svg
101
+ [🏘depfu♻️]: https://depfu.com/github/oauth-xx/oauth-ruby?project_id=22868
102
+ [🏘depfu-img♻️]: https://badges.depfu.com/badges/d570491bac0ad3b0b65deb3c82028327/count.svg
103
+ [🚎contributors]: https://github.com/oauth-xx/oauth-ruby/graphs/contributors
104
+ [🚎contributors-img]: https://img.shields.io/github/contributors-anon/oauth-xx/oauth-ruby
105
+ [🖐style-wf]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/style.yml
106
+ [🖐style-wf-img]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/style.yml/badge.svg
107
+ [🧮kloc]: https://www.youtube.com/watch?v=dQw4w9WgXcQ
108
+ [🧮kloc-img]: https://img.shields.io/tokei/lines/github.com/oauth-xx/oauth-ruby
109
+
110
+ <!-- 4️⃣ testing -->
111
+ [⛳iss-o]: https://github.com/oauth-xx/oauth-ruby/issues
112
+ [⛳iss-o-img]: https://img.shields.io/github/issues-raw/oauth-xx/oauth-ruby
113
+ [🖇iss-c]: https://github.com/oauth-xx/oauth-ruby/issues?q=is%3Aissue+is%3Aclosed
114
+ [🖇iss-c-img]: https://img.shields.io/github/issues-closed-raw/oauth-xx/oauth-ruby
115
+ [🏘sup-wf]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/supported.yml
116
+ [🏘sup-wf-img]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/supported.yml/badge.svg
117
+ [🚎heads-wf]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/heads.yml
118
+ [🚎heads-wf-img]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/heads.yml/badge.svg
119
+ [🖐uns-wf]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/unsupported.yml
120
+ [🖐uns-wf-img]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/unsupported.yml/badge.svg
121
+ [🧮mac-wf]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/macos.yml
122
+ [🧮mac-wf-img]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/macos.yml/badge.svg
123
+ [📗win-wf]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/windows.yml
124
+ [📗win-wf-img]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/windows.yml/badge.svg
125
+
126
+ <!-- 5️⃣ coverage & security -->
127
+ [⛳cclim-cov]: https://codeclimate.com/github/oauth-xx/oauth-ruby/test_coverage
128
+ [⛳cclim-cov-img♻️]: https://api.codeclimate.com/v1/badges/3cf23270c21e8791d788/test_coverage
129
+ [🖇codecov-img♻️]: https://codecov.io/gh/oauth-xx/oauth-ruby/branch/main/graph/badge.svg?token=4ZNAWNxrf9
130
+ [🖇codecov]: https://codecov.io/gh/oauth-xx/oauth-ruby
131
+ [🏘coveralls]: https://coveralls.io/github/oauth-xx/oauth-ruby?branch=main
132
+ [🏘coveralls-img]: https://coveralls.io/repos/github/oauth-xx/oauth-ruby/badge.svg?branch=main
133
+ [🚎sec-pol]: https://github.com/oauth-xx/oauth-ruby/blob/main/SECURITY.md
134
+ [🚎sec-pol-img]: https://img.shields.io/badge/security-policy-brightgreen.svg?style=flat
135
+ [🖐codeQL]: https://github.com/oauth-xx/oauth-ruby/security/code-scanning
136
+ [🖐codeQL-img]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/codeql-analysis.yml/badge.svg
137
+ [🧮cov-wf]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/coverage.yml
138
+ [🧮cov-wf-img]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/coverage.yml/badge.svg
139
+
140
+ <!-- 6️⃣ resources -->
141
+ [⛳gh-discussions]: https://github.com/oauth-xx/oauth-ruby/discussions
142
+ [⛳gh-discussions-img]: https://img.shields.io/github/discussions/oauth-xx/oauth-ruby
143
+ [🖇codementor]: https://www.codementor.io/peterboling?utm_source=github&utm_medium=button&utm_term=peterboling&utm_campaign=github
144
+ [🖇codementor-img]: https://cdn.codementor.io/badges/get_help_github.svg
145
+ [🏘chat]: https://gitter.im/oauth-xx/oauth-ruby
146
+ [🏘chat-img]: https://img.shields.io/gitter/room/oauth-xx/oauth-ruby.svg
147
+ [🚎blog]: http://www.railsbling.com/tags/oauth-ruby/
148
+ [🚎blog-img]: https://img.shields.io/badge/blog-railsbling-brightgreen.svg?style=flat
149
+ [🖐wiki]: https://github.com/oauth-xx/oauth-ruby/wiki
150
+ [🖐wiki-img]: https://img.shields.io/badge/wiki-examples-brightgreen.svg?style=flat
151
+
152
+ <!-- 7️⃣ spread 💖 -->
153
+ [⛳liberapay-img]: https://img.shields.io/liberapay/patrons/pboling.svg?logo=liberapay
154
+ [⛳liberapay]: https://liberapay.com/pboling/donate
155
+ [🖇sponsor-img]: https://img.shields.io/badge/sponsor-pboling.svg?style=social&logo=github
156
+ [🖇sponsor]: https://github.com/sponsors/pboling
157
+ [🏘tweet-img]: https://img.shields.io/twitter/follow/galtzo.svg?style=social&label=Follow
158
+ [🏘tweet]: http://twitter.com/galtzo
159
+
160
+ <!-- Maintainer Contact Links -->
161
+ [railsbling]: http://www.railsbling.com
162
+ [peterboling]: http://www.peterboling.com
163
+
164
+ ## Installation
165
+
166
+ Install the gem and add to the application's Gemfile by executing:
167
+
168
+ $ bundle add oauth
169
+
170
+ If bundler is not being used to manage dependencies, install the gem by executing:
171
+
172
+ $ gem install oauth
173
+
174
+ ## OAuth for Enterprise
175
+
176
+ Available as part of the Tidelift Subscription.
177
+
178
+ 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.](https://tidelift.com/subscription/pkg/rubygems-oauth?utm_source=rubygems-oauth&utm_medium=referral&utm_campaign=enterprise)
179
+
180
+ ## Security contact information [![Security Policy][🚎sec-pol-img]][🚎sec-pol]
181
+
182
+ To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security).
183
+ Tidelift will coordinate the fix and disclosure.
184
+
185
+ For more see [SECURITY.md][🚎sec-pol].
186
+
187
+ ## Compatibility
188
+
189
+ Targeted ruby compatibility is non-EOL versions of Ruby, currently 2.7, 3.0, and
190
+ 3.1. Ruby is limited to 2.4+ in the gemspec, and this will change with minor version bumps,
191
+ while the gem is still in 0.x, in accordance with the SemVer spec.
192
+
193
+ The `main` branch now targets 1.0.x releases.
194
+ See `v0.6-maintenance` branch for Ruby >= 2.4.
195
+ See `v0.5-maintenance` branch for Ruby >= 2.0.
196
+
197
+ NOTE: No further releases of version < 1.0.x are anticipated.
198
+
199
+ <details>
200
+ <summary>Ruby Engine Compatibility Policy</summary>
201
+
202
+ This gem is tested against MRI, and to a lesser extent, against JRuby, and Truffleruby.
203
+ Each of those has varying versions that target a specific version of MRI Ruby.
204
+ This gem should work in the just-listed Ruby engines according to the targeted MRI compatibility in the table below.
205
+ If you would like to add support for additional engines,
206
+ first make sure Github Actions supports the engine,
207
+ then submit a PR to the correct maintenance branch as according to the table below.
208
+ </details>
209
+
210
+ <details>
211
+ <summary>Ruby Version Compatibility Policy</summary>
212
+
213
+ If something doesn't work on one of these interpreters, it's a bug.
214
+
215
+ This library may inadvertently work (or seem to work) on other Ruby
216
+ implementations, however support will only be provided for the versions listed
217
+ above.
218
+
219
+ If you would like this library to support another Ruby version, you may
220
+ volunteer to be a maintainer. Being a maintainer entails making sure all tests
221
+ run and pass on that implementation. When something breaks on your
222
+ implementation, you will be responsible for providing patches in a timely
223
+ fashion. If critical issues for a particular implementation exist at the time
224
+ of a major release, support for that Ruby version may be dropped.
225
+ </details>
226
+
227
+ | | Ruby OAuth Version | Maintenance Branch | 🚂 Compatibility | Official 💎 | Unofficial 💎 | Incidental 💎 |
228
+ |:----|--------------------|--------------------|------------------------|----------------------|------------------------------|---------------|
229
+ | 1️⃣ | 1.0.x | `main` | Rails 6, 7 | 2.7, 3.0, 3.1 | sorry, not sorry | nope |
230
+ | 2️⃣ | 0.6.x | `v0.6-maintenance` | Rails 5, 6, 7 | 2.7, 3.0, 3.1 | 2.5, 2.6 | 2.4 |
231
+ | 3️⃣ | 0.5.x | `v0.5-maintenance` | Rails 2, 3, 4, 5, 6, 7 | 2.7, 3.0, 3.1 | 2.1, 2.2, 2.3, 2.4, 2.5, 2.6 | 2.0 |
232
+ | 4️⃣ | older | N/A | | Best of luck to you! | Please upgrade! | noop |
233
+
234
+ NOTE: Once 1.0 is released, the 0.x series will only receive critical bug and security updates.
235
+ See [SECURITY.md][🚎sec-pol]
236
+
237
+ 🚂 NOTE: See notes on Rails in next section.
238
+
239
+ ## Basics
240
+
241
+ This is a ruby library which is intended to be used in creating Ruby Consumer
242
+ and Service Provider applications. It is NOT a Rails plugin, but could easily
243
+ be used for the foundation for such a Rails plugin.
244
+
245
+ This gem was originally extracted from @pelle's [oauth-plugin](https://github.com/pelle/oauth-plugin)
246
+ gem. After extraction that gem was made to depend on this gem.
247
+
248
+ Unfortunately, this gem does have some Rails related bits that are
249
+ **optional** to load. You don't need Rails! The Rails bits may be pulled out
250
+ into a separate gem with the release of version 1.0 of this gem.
251
+
252
+ ## Usage
253
+
254
+ We need to specify the `oauth_callback` url explicitly, otherwise it defaults to
255
+ "oob" (Out of Band)
256
+
257
+ ```ruby
258
+ callback_url = "http://127.0.0.1:3000/oauth/callback"
259
+ ```
260
+
261
+ Create a new `OAuth::Consumer` instance by passing it a configuration hash:
262
+
263
+ ```ruby
264
+ oauth_consumer = OAuth::Consumer.new("key", "secret", site: "https://agree2")
265
+ ```
266
+
267
+ Start the process by requesting a token
268
+
269
+ ```ruby
270
+ request_token = oauth_consumer.get_request_token(oauth_callback: callback_url)
271
+
272
+ session[:token] = request_token.token
273
+ session[:token_secret] = request_token.secret
274
+ redirect_to request_token.authorize_url(oauth_callback: callback_url)
275
+ ```
276
+
277
+ When user returns create an access_token
278
+
279
+ ```ruby
280
+ hash = { oauth_token: session[:token], oauth_token_secret: session[:token_secret] }
281
+ request_token = OAuth::RequestToken.from_hash(oauth_consumer, hash)
282
+ access_token = request_token.get_access_token
283
+ # For 3-legged authorization, flow oauth_verifier is passed as param in callback
284
+ # access_token = request_token.get_access_token(oauth_verifier: params[:oauth_verifier])
285
+ @photos = access_token.get("/photos.xml")
286
+ ```
287
+
288
+ Now that you have an access token, you can use Typhoeus to interact with the
289
+ OAuth provider if you choose.
290
+
291
+ ```ruby
292
+ require "typhoeus"
293
+ require "oauth/request_proxy/typhoeus_request"
294
+ oauth_params = { consumer: oauth_consumer, token: access_token }
295
+ hydra = Typhoeus::Hydra.new
296
+ req = Typhoeus::Request.new(uri, options) # :method needs to be specified in options
297
+ oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(request_uri: uri))
298
+ req.options[:headers]["Authorization"] = oauth_helper.header # Signs the request
299
+ hydra.queue(req)
300
+ hydra.run
301
+ @response = req.response
302
+ ```
303
+
304
+ ## More Information
305
+
306
+ * RubyDoc Documentation: [![RubyDoc.info](https://img.shields.io/badge/documentation-rubydoc-brightgreen.svg?style=flat)][documentation]
307
+ * Mailing List/Google Group: [![Mailing List](https://img.shields.io/badge/group-mailinglist-violet.svg?style=social&logo=google)][mailinglist]
308
+ * GitHub Discussions: [![Discussion](https://img.shields.io/badge/discussions-github-brightgreen.svg?style=flat)][gh_discussions]
309
+ * Live Chat on Gitter: [![Join the chat at https://gitter.im/oauth-xx/oauth-ruby](https://badges.gitter.im/Join%20Chat.svg)][chat]
310
+ * Maintainer's Blog: [![Blog](https://img.shields.io/badge/blog-railsbling-brightgreen.svg?style=flat)][blogpage]
311
+
312
+ ## Contributing
313
+
314
+ See [CONTRIBUTING.md][contributing]
315
+
316
+ ## Contributors
317
+
318
+ [![Contributors](https://contrib.rocks/image?repo=oauth-xx/oauth-ruby)][contributors]
319
+
320
+ Made with [contributors-img][contrib-rocks].
321
+
322
+ ## Versioning
323
+
324
+ This library aims to adhere to [Semantic Versioning 2.0.0][semver]. Violations of this scheme should be reported as
325
+ bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, a new version should be
326
+ immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new
327
+ major versions. Compatibility with a major and minor versions of Ruby will only be changed with a major version bump.
328
+
329
+ As a result of this policy, you can (and should) specify a dependency on this gem using
330
+ the [Pessimistic Version Constraint][pvc] with two digits of precision.
331
+
332
+ For example:
333
+
334
+ ```ruby
335
+ spec.add_dependency "oauth", "~> 0.6.2"
336
+ ```
337
+
338
+ ## License
339
+
340
+ The gem is available as open source under the terms of
341
+ the [MIT License][license] [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)][license-ref].
342
+ See [LICENSE][license] for the [Copyright Notice][copyright-notice-explainer].
343
+
344
+ ## Contact
345
+
346
+ OAuth Ruby has been created and maintained by a large number of talented
347
+ individuals. The current maintainer is Peter Boling ([@pboling][gh_sponsors]).
348
+
349
+ Comments are welcome. Contact the [OAuth Ruby mailing list (Google Group)][mailinglist] or [GitHub Discussions][gh_discussions].
350
+
351
+ [comment]: <> (Following links are used by README, CONTRIBUTING, Homepage)
352
+
353
+ [conduct]: https://github.com/oauth-xx/oauth-ruby/blob/main/CODE_OF_CONDUCT.md
354
+ [contributing]: https://github.com/oauth-xx/oauth-ruby/blob/main/CONTRIBUTING.md
355
+ [contributors]: https://github.com/oauth-xx/oauth-ruby/graphs/contributors
356
+ [mailinglist]: http://groups.google.com/group/oauth-ruby
357
+ [source]: https://github.com/oauth-xx/oauth-ruby/
358
+
359
+ [comment]: <> (Following links are used by README, Homepage)
360
+
361
+ [aboutme]: https://about.me/peter.boling
362
+ [actions]: https://github.com/oauth-xx/oauth-ruby/actions
363
+ [angelme]: https://angel.co/peter-boling
364
+ [blogpage]: http://www.railsbling.com/tags/oauth/
365
+ [chat]: https://gitter.im/oauth-xx/oauth-ruby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
366
+ [climate_coverage]: https://codeclimate.com/github/oauth-xx/oauth-ruby/test_coverage
367
+ [climate_maintainability]: https://codeclimate.com/github/oauth-xx/oauth-ruby/maintainability
368
+ [code_triage]: https://www.codetriage.com/oauth-xx/oauth-ruby
369
+ [codecov_coverage]: https://codecov.io/gh/oauth-xx/oauth-ruby
370
+ [coderme]:http://coderwall.com/pboling
371
+ [depfu]: https://depfu.com/github/oauth-xx/oauth-ruby?project_id=22868
372
+ [documentation]: https://rubydoc.info/github/oauth-xx/oauth-ruby
373
+ [followme-img]: https://img.shields.io/twitter/follow/galtzo.svg?style=social&label=Follow
374
+ [gh_discussions]: https://github.com/oauth-xx/oauth-ruby/discussions
375
+ [gh_sponsors]: https://github.com/sponsors/pboling
376
+ [license]: https://github.com/oauth-xx/oauth-ruby/blob/main/LICENSE
377
+ [license-ref]: https://opensource.org/licenses/MIT
378
+ [liberapay_donate]: https://liberapay.com/pboling/donate
379
+ [pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint
380
+ [rubygems]: https://rubygems.org/gems/oauth
381
+ [security]: https://github.com/oauth-xx/oauth-ruby/blob/main/SECURITY.md
382
+ [semver]: http://semver.org/
383
+ [tweetme]: http://twitter.com/galtzo
data/SECURITY.md ADDED
@@ -0,0 +1,20 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ |---------|--------------------|
7
+ | 0.6.x | :white_check_mark: |
8
+ | 0.5.x | :white_check_mark: |
9
+ | <= 0.5 | :x: |
10
+
11
+ ## Reporting a Vulnerability
12
+
13
+ To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security).
14
+ Tidelift will coordinate the fix and disclosure.
15
+
16
+ ## OAuth for Enterprise
17
+
18
+ Available as part of the Tidelift Subscription.
19
+
20
+ The maintainers of oauth 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.](https://tidelift.com/subscription/pkg/rubygems-oauth?utm_source=rubygems-oauth&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
data/bin/oauth CHANGED
@@ -1,11 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require_relative "../lib/oauth"
4
- require 'oauth/cli'
4
+ require "oauth"
5
+ require "oauth/cli"
5
6
 
6
- Signal.trap("INT") { puts; exit(1) } # don't dump a backtrace on a ^C
7
-
8
- ARGV << 'help' if ARGV.empty?
7
+ # don't dump a backtrace on a ^C
8
+ Signal.trap("INT") do
9
+ puts
10
+ exit(1)
11
+ end
12
+ ARGV << "help" if ARGV.empty?
9
13
  command = ARGV.shift
10
14
 
11
- OAuth::CLI.new(STDOUT, STDIN, STDERR, command, ARGV).run
15
+ OAuth::CLI.new($stdout, $stdin, $stderr, command, ARGV).run
@@ -1,71 +1,73 @@
1
- class OAuth::CLI
2
- class AuthorizeCommand < BaseCommand
1
+ # frozen_string_literal: true
3
2
 
4
- def required_options
5
- [:uri]
6
- end
7
-
8
- def _run
9
- request_token = get_request_token
10
-
11
- if request_token.callback_confirmed?
12
- puts "Server appears to support OAuth 1.0a; enabling support."
13
- options[:version] = "1.0a"
3
+ module OAuth
4
+ class CLI
5
+ class AuthorizeCommand < BaseCommand
6
+ def required_options
7
+ [:uri]
14
8
  end
15
9
 
16
- puts "Please visit this url to authorize:"
17
- puts request_token.authorize_url
10
+ def _run
11
+ request_token = get_request_token
18
12
 
19
- # parameters for OAuth 1.0a
20
- oauth_verifier = ask_user_for_verifier
13
+ if request_token.callback_confirmed?
14
+ puts "Server appears to support OAuth 1.0a; enabling support."
15
+ options[:version] = "1.0a"
16
+ end
21
17
 
22
- verbosely_get_access_token(request_token, oauth_verifier)
23
- end
18
+ puts "Please visit this url to authorize:"
19
+ puts request_token.authorize_url
24
20
 
25
- def get_request_token
26
- consumer = get_consumer
27
- scope_options = options[:scope] ? { "scope" => options[:scope] } : {}
28
- consumer.get_request_token({ :oauth_callback => options[:oauth_callback] }, scope_options)
29
- rescue OAuth::Unauthorized => e
30
- alert "A problem occurred while attempting to authorize:"
31
- alert e
32
- alert e.request.body
33
- end
21
+ # parameters for OAuth 1.0a
22
+ oauth_verifier = ask_user_for_verifier
34
23
 
35
- def get_consumer
36
- OAuth::Consumer.new \
37
- options[:oauth_consumer_key],
38
- options[:oauth_consumer_secret],
39
- :access_token_url => options[:access_token_url],
40
- :authorize_url => options[:authorize_url],
41
- :request_token_url => options[:request_token_url],
42
- :scheme => options[:scheme],
43
- :http_method => options[:method].to_s.downcase.to_sym
44
- end
24
+ verbosely_get_access_token(request_token, oauth_verifier)
25
+ end
45
26
 
27
+ def get_request_token
28
+ consumer = get_consumer
29
+ scope_options = options[:scope] ? { "scope" => options[:scope] } : {}
30
+ consumer.get_request_token({ oauth_callback: options[:oauth_callback] }, scope_options)
31
+ rescue OAuth::Unauthorized => e
32
+ alert "A problem occurred while attempting to authorize:"
33
+ alert e
34
+ alert e.request.body
35
+ end
46
36
 
47
- def ask_user_for_verifier
48
- if options[:version] == "1.0a"
49
- puts "Please enter the verification code provided by the SP (oauth_verifier):"
50
- @stdin.gets.chomp
51
- else
52
- puts "Press return to continue..."
53
- @stdin.gets
54
- nil
37
+ def get_consumer
38
+ OAuth::Consumer.new \
39
+ options[:oauth_consumer_key],
40
+ options[:oauth_consumer_secret],
41
+ access_token_url: options[:access_token_url],
42
+ authorize_url: options[:authorize_url],
43
+ request_token_url: options[:request_token_url],
44
+ scheme: options[:scheme],
45
+ http_method: options[:method].to_s.downcase.to_sym
46
+ end
47
+
48
+ def ask_user_for_verifier
49
+ if options[:version] == "1.0a"
50
+ puts "Please enter the verification code provided by the SP (oauth_verifier):"
51
+ @stdin.gets.chomp
52
+ else
53
+ puts "Press return to continue..."
54
+ @stdin.gets
55
+ nil
56
+ end
55
57
  end
56
- end
57
58
 
58
- def verbosely_get_access_token(request_token, oauth_verifier)
59
- access_token = request_token.get_access_token(:oauth_verifier => oauth_verifier)
59
+ def verbosely_get_access_token(request_token, oauth_verifier)
60
+ access_token = request_token.get_access_token(oauth_verifier: oauth_verifier)
60
61
 
61
- puts "Response:"
62
- access_token.params.each do |k,v|
63
- puts " #{k}: #{v}" unless k.is_a?(Symbol)
62
+ puts "Response:"
63
+ access_token.params.each do |k, v|
64
+ puts " #{k}: #{v}" unless k.is_a?(Symbol)
65
+ end
66
+ rescue OAuth::Unauthorized => e
67
+ alert "A problem occurred while attempting to obtain an access token:"
68
+ alert e
69
+ alert e.request.body
64
70
  end
65
- rescue OAuth::Unauthorized => e
66
- alert "A problem occurred while attempting to obtain an access token:"
67
- alert e
68
- alert e.request.body
69
71
  end
70
72
  end
71
73
  end