oauth 0.5.12 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +41 -3
  3. data/README.md +56 -46
  4. data/SECURITY.md +0 -2
  5. data/bin/oauth +8 -4
  6. data/lib/oauth/cli/authorize_command.rb +58 -54
  7. data/lib/oauth/cli/base_command.rb +163 -159
  8. data/lib/oauth/cli/help_command.rb +9 -5
  9. data/lib/oauth/cli/query_command.rb +26 -17
  10. data/lib/oauth/cli/sign_command.rb +58 -52
  11. data/lib/oauth/cli/version_command.rb +8 -4
  12. data/lib/oauth/cli.rb +2 -0
  13. data/lib/oauth/client/action_controller_request.rb +4 -1
  14. data/lib/oauth/client/em_http.rb +3 -1
  15. data/lib/oauth/client/helper.rb +76 -72
  16. data/lib/oauth/client/net_http.rb +111 -104
  17. data/lib/oauth/client.rb +2 -0
  18. data/lib/oauth/consumer.rb +50 -32
  19. data/lib/oauth/errors/error.rb +2 -0
  20. data/lib/oauth/errors/problem.rb +3 -0
  21. data/lib/oauth/errors/unauthorized.rb +4 -0
  22. data/lib/oauth/errors.rb +2 -0
  23. data/lib/oauth/helper.rb +9 -5
  24. data/lib/oauth/oauth.rb +4 -2
  25. data/lib/oauth/oauth_test_helper.rb +2 -0
  26. data/lib/oauth/request_proxy/base.rb +4 -4
  27. data/lib/oauth/request_proxy/mock_request.rb +1 -1
  28. data/lib/oauth/request_proxy/net_http.rb +8 -8
  29. data/lib/oauth/request_proxy/rest_client_request.rb +4 -3
  30. data/lib/oauth/request_proxy.rb +4 -1
  31. data/lib/oauth/server.rb +8 -4
  32. data/lib/oauth/signature/base.rb +73 -65
  33. data/lib/oauth/signature/hmac/sha1.rb +15 -9
  34. data/lib/oauth/signature/hmac/sha256.rb +15 -9
  35. data/lib/oauth/signature/plaintext.rb +18 -20
  36. data/lib/oauth/signature/rsa/sha1.rb +46 -38
  37. data/lib/oauth/signature.rb +3 -0
  38. data/lib/oauth/token.rb +2 -0
  39. data/lib/oauth/tokens/access_token.rb +2 -0
  40. data/lib/oauth/tokens/consumer_token.rb +2 -0
  41. data/lib/oauth/tokens/request_token.rb +5 -2
  42. data/lib/oauth/tokens/server_token.rb +2 -0
  43. data/lib/oauth/tokens/token.rb +2 -0
  44. data/lib/oauth/version.rb +5 -1
  45. data/lib/oauth.rb +8 -2
  46. metadata +29 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1383760af4fa4c23f17387391201215fae2fb7547e5416f47b293f53a1cf95a5
4
- data.tar.gz: 60b6383d43251da5bd3f410fd08cb4b537b82bc9a4ceda74a18803deb5282781
3
+ metadata.gz: 414ee66cdf6d7d20e2caddba76264dc3a5d5d058157abe8cd77907cfe42e2fbe
4
+ data.tar.gz: de2152db1bf49cb9397bb95eaf10ebbe67f755f3de478cb36e4350beda3b2b5f
5
5
  SHA512:
6
- metadata.gz: f4ccb62d26bcfa62ca0b7f1bf578d3e4f4d0a1c97c59289843450c67bfdf5dd3793eefc1fd4d6c533447f95bb229d85192677b8711bfdad56843ea0ddc82677f
7
- data.tar.gz: eb3f300e571daee4cd9ca6fedf75eaefaf0a315469651949a24a8786d6474353b374121379dd52acd3a72b2f580a87fd2ac3443436d447083da87913784b16ec
6
+ metadata.gz: 2ab63e0e09c842637f45bf7053eae8c834238b36cee7ae8771a70766c51cea0a1b1277c025a46caa9fb5499fd93ff342749dc42e70bb5a3351a169b894602f0d
7
+ data.tar.gz: aca6573f60c0926534fa3f6b1e40695c3ddb96ee9153cc9a3bc3bf6948d831918c1f358afde4273eca4a9608b2e20cc75e8b86a2e9cc53ab257d1084a6130e0a
data/CHANGELOG.md CHANGED
@@ -13,11 +13,45 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13
13
 
14
14
  ### Removed
15
15
 
16
+ ## [0.6.1] 2022-08-23
17
+ ### Changed
18
+ * Fixed documentation in SECURITY.md
19
+ * Change references to master => main
20
+
21
+ ### Added
22
+ * Post install note about v0.6.x EOL approaching in April, 2024
23
+
24
+ ## [0.6.0] 2022-08-23
25
+ ### Added
26
+ * New option `body_hash_enabled` which defaults to true to maintain backward compatibility with prior releases. Setting to `false` disables generation of a `oauth_body_hash` component as part of the signature computation.
27
+ * Improved documentation of support policy via Tidelift
28
+ * Stop testing against active_support v2
29
+
30
+ ### Changed
31
+ * Utilize version_gem extracted from oauth2 gem for VERSION
32
+ * Added new `OAuth::Version` namespace
33
+ * VERSION constant now at `OAuth::Version::VERSION`
34
+
35
+ ### Removed
36
+ * Ruby 2.0, 2.1, 2.2, and 2.3 are no longer valid install targets
37
+
38
+ ## [0.5.13] 2022-08-23
39
+ The "I think I caught 'em all!" Release
40
+
41
+ ### Fixed
42
+ * Typo oauth2 => oauth as gem name in one more place.
43
+
44
+ ## [0.5.12] 2022-08-23
45
+ The "Typoes are just the worst!" Release
46
+
47
+ ### Fixed
48
+ * Typo oauth2 => oauth as gem name in a couple places.
49
+
16
50
  ## [0.5.11] 2022-08-23
17
51
  The "Is this the last release with a silly name?" Release
18
52
 
19
53
  ### Added
20
- * Post install note about EOL approaching in April, 2023
54
+ * Post install note about v0.5.x EOL approaching in April, 2023
21
55
 
22
56
  ### Changed
23
57
  * Improved documentation
@@ -299,7 +333,7 @@ The "Can it be the end of the line for 0.5.x?" Release
299
333
 
300
334
  ## [0.3.4] 2009-05-06
301
335
  ### Changed
302
- * OAuth::Client::Helper uses OAuth::VERSION (chadisfaction)
336
+ * OAuth::Client::Helper uses OAuth::Version::VERSION (chadisfaction)
303
337
 
304
338
  ### Fixed
305
339
  * Fix OAuth::RequestProxy::ActionControllerRequest's handling of params (Tristan Groléat)
@@ -397,7 +431,11 @@ but please have a look at the unit tests.
397
431
  * Moved all non-Rails functionality from the Rails plugin:
398
432
  http://code.google.com/p/oauth-plugin/
399
433
 
400
- [Unreleased]: https://github.com/oauth-xx/oauth-ruby/compare/v0.5.11...v0.5-maintenance
434
+ [Unreleased]: https://github.com/oauth-xx/oauth-ruby/compare/v0.6.1...v0.6-maintenance
435
+ [0.6.1]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v0.6.1
436
+ [0.6.0]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v0.6.0
437
+ [0.5.13]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v0.5.13
438
+ [0.5.12]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v0.5.12
401
439
  [0.5.11]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v0.5.11
402
440
  [0.5.10]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v0.5.10
403
441
  [0.5.9]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v0.5.9
data/README.md CHANGED
@@ -22,8 +22,8 @@ See the sibling `oauth2` gem for OAuth 2.0 implementations in Ruby.
22
22
 
23
23
  **NOTE**
24
24
 
25
- This README, on branch `v0.5-maintenance`, targets 0.5.x series releases.
26
- The v0.5.x series of releases will be EOL no later than April, 2023.
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
27
  For later releases please see the `main` branch README.
28
28
 
29
29
  ## Status
@@ -55,15 +55,15 @@ appended indicators:
55
55
  ♻️ - URL needs to be updated from SASS integration. Find / Replace is insufficient.
56
56
  -->
57
57
 
58
- | | Project | bundle add oauth2 |
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] |
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] |
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
67
 
68
68
  <!--
69
69
  The link tokens in the following sections should be kept ordered by the row and badge numbering scheme
@@ -187,12 +187,14 @@ For more see [SECURITY.md][🚎sec-pol].
187
187
  ## Compatibility
188
188
 
189
189
  Targeted ruby compatibility is non-EOL versions of Ruby, currently 2.7, 3.0, and
190
- 3.1. Ruby is limited to 2.0+ in the gemspec on this `v0.5-maintenance` branch.
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.
191
192
 
192
- The `v0.6-maintenance` branch targets 0.6.x releases.
193
- See `v0.5-maintenance` branch for older rubies.
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.
194
196
 
195
- NOTE: No further releases of the 0.5.x series are anticipated.
197
+ NOTE: No further releases of version < 1.0.x are anticipated.
196
198
 
197
199
  <details>
198
200
  <summary>Ruby Engine Compatibility Policy</summary>
@@ -222,17 +224,18 @@ fashion. If critical issues for a particular implementation exist at the time
222
224
  of a major release, support for that Ruby version may be dropped.
223
225
  </details>
224
226
 
225
- | | Ruby OAuth Version | Maintenance Branch | 🚂 Compatibility | Official 💎 | Unofficial 💎 | Incidental 💎 |
226
- |:----|--------------------|--------------------|------------------------|----------------------|-------------------------|---------------|
227
- | 1️⃣ | 1.0.x | `main` | Rails 6, 7 | 2.7, 3.0, 3.1 | sorry, not sorry | nope |
228
- | 2️⃣ | 0.6.x | `v0.6-maintenance` | Rails 5, 6, 7 | 2.7, 3.0, 3.1 | 2.5, 2.6 | 2.4 |
229
- | 3️⃣ | 0.5.x | `v0.5-maintenance` | Rails 2, 3, 4, 5, 6, 7 | 2.7, 3.0, 3.1 | 2.2, 2.3, 2.4, 2.5, 2.6 | 2.0, 2.1 |
230
- | 4️⃣ | older | N/A | | Best of luck to you! | Please upgrade! | noop |
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 |
231
233
 
232
- NOTE: Support for version 0.5.x will end in April, 2023
233
234
  NOTE: Once 1.0 is released, the 0.x series will only receive critical bug and security updates.
234
235
  See [SECURITY.md][🚎sec-pol]
235
236
 
237
+ 🚂 NOTE: See notes on Rails in next section.
238
+
236
239
  ## Basics
237
240
 
238
241
  This is a ruby library which is intended to be used in creating Ruby Consumer
@@ -257,38 +260,46 @@ callback_url = "http://127.0.0.1:3000/oauth/callback"
257
260
 
258
261
  Create a new `OAuth::Consumer` instance by passing it a configuration hash:
259
262
 
260
- oauth_consumer = OAuth::Consumer.new("key", "secret", :site => "https://agree2")
263
+ ```ruby
264
+ oauth_consumer = OAuth::Consumer.new("key", "secret", site: "https://agree2")
265
+ ```
261
266
 
262
267
  Start the process by requesting a token
263
268
 
264
- request_token = oauth_consumer.get_request_token(:oauth_callback => callback_url)
269
+ ```ruby
270
+ request_token = oauth_consumer.get_request_token(oauth_callback: callback_url)
265
271
 
266
- session[:token] = request_token.token
267
- session[:token_secret] = request_token.secret
268
- redirect_to request_token.authorize_url(:oauth_callback => callback_url)
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
+ ```
269
276
 
270
277
  When user returns create an access_token
271
278
 
272
- hash = { oauth_token: session[:token], oauth_token_secret: session[:token_secret]}
273
- request_token = OAuth::RequestToken.from_hash(oauth_consumer, hash)
274
- access_token = request_token.get_access_token
275
- # For 3-legged authorization, flow oauth_verifier is passed as param in callback
276
- # access_token = request_token.get_access_token(oauth_verifier: params[:oauth_verifier])
277
- @photos = access_token.get('/photos.xml')
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
+ ```
278
287
 
279
288
  Now that you have an access token, you can use Typhoeus to interact with the
280
289
  OAuth provider if you choose.
281
290
 
282
- require 'typhoeus'
283
- require 'oauth/request_proxy/typhoeus_request'
284
- oauth_params = {:consumer => oauth_consumer, :token => access_token}
285
- hydra = Typhoeus::Hydra.new
286
- req = Typhoeus::Request.new(uri, options) # :method needs to be specified in options
287
- oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(:request_uri => uri))
288
- req.options[:headers].merge!({"Authorization" => oauth_helper.header}) # Signs the request
289
- hydra.queue(req)
290
- hydra.run
291
- @response = req.response
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
+ ```
292
303
 
293
304
  ## More Information
294
305
 
@@ -316,13 +327,12 @@ immediately released that restores compatibility. Breaking changes to the public
316
327
  major versions. Compatibility with a major and minor versions of Ruby will only be changed with a major version bump.
317
328
 
318
329
  As a result of this policy, you can (and should) specify a dependency on this gem using
319
- the [Pessimistic Version Constraint][pvc] with two digits of precision once it hits a 1.0 release.
320
- While on 0.x releases three digits of precision should be used.
330
+ the [Pessimistic Version Constraint][pvc] with two digits of precision.
321
331
 
322
332
  For example:
323
333
 
324
334
  ```ruby
325
- spec.add_dependency "oauth", "~> 0.5.10"
335
+ spec.add_dependency "oauth", "~> 0.6.0"
326
336
  ```
327
337
 
328
338
  ## License
data/SECURITY.md CHANGED
@@ -8,8 +8,6 @@
8
8
  | 0.5.x | :white_check_mark: |
9
9
  | <= 0.5 | :x: |
10
10
 
11
- NOTE: Support for version 0.5.x will end in April, 2023
12
-
13
11
  ## Reporting a Vulnerability
14
12
 
15
13
  To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security).
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"
4
5
  require "oauth/cli"
5
6
 
6
- Signal.trap("INT") { puts; exit(1) } # don't dump a backtrace on a ^C
7
-
7
+ # don't dump a backtrace on a ^C
8
+ Signal.trap("INT") do
9
+ puts
10
+ exit(1)
11
+ end
8
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,69 +1,73 @@
1
- class OAuth::CLI
2
- class AuthorizeCommand < BaseCommand
3
- def required_options
4
- [:uri]
5
- end
6
-
7
- def _run
8
- request_token = get_request_token
1
+ # frozen_string_literal: true
9
2
 
10
- if request_token.callback_confirmed?
11
- puts "Server appears to support OAuth 1.0a; enabling support."
12
- options[:version] = "1.0a"
3
+ module OAuth
4
+ class CLI
5
+ class AuthorizeCommand < BaseCommand
6
+ def required_options
7
+ [:uri]
13
8
  end
14
9
 
15
- puts "Please visit this url to authorize:"
16
- puts request_token.authorize_url
10
+ def _run
11
+ request_token = get_request_token
17
12
 
18
- # parameters for OAuth 1.0a
19
- 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
20
17
 
21
- verbosely_get_access_token(request_token, oauth_verifier)
22
- end
18
+ puts "Please visit this url to authorize:"
19
+ puts request_token.authorize_url
23
20
 
24
- def get_request_token
25
- consumer = get_consumer
26
- scope_options = options[:scope] ? { "scope" => options[:scope] } : {}
27
- consumer.get_request_token({ oauth_callback: options[:oauth_callback] }, scope_options)
28
- rescue OAuth::Unauthorized => e
29
- alert "A problem occurred while attempting to authorize:"
30
- alert e
31
- alert e.request.body
32
- end
21
+ # parameters for OAuth 1.0a
22
+ oauth_verifier = ask_user_for_verifier
33
23
 
34
- def get_consumer
35
- OAuth::Consumer.new \
36
- options[:oauth_consumer_key],
37
- options[:oauth_consumer_secret],
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
43
- end
24
+ verbosely_get_access_token(request_token, oauth_verifier)
25
+ end
44
26
 
45
- def ask_user_for_verifier
46
- if options[:version] == "1.0a"
47
- puts "Please enter the verification code provided by the SP (oauth_verifier):"
48
- @stdin.gets.chomp
49
- else
50
- puts "Press return to continue..."
51
- @stdin.gets
52
- nil
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
36
+
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
53
57
  end
54
- end
55
58
 
56
- def verbosely_get_access_token(request_token, oauth_verifier)
57
- 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)
58
61
 
59
- puts "Response:"
60
- access_token.params.each do |k, v|
61
- 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
62
70
  end
63
- rescue OAuth::Unauthorized => e
64
- alert "A problem occurred while attempting to obtain an access token:"
65
- alert e
66
- alert e.request.body
67
71
  end
68
72
  end
69
73
  end