oauth 0.5.5 → 0.5.10

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