oauth 0.5.14 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -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 +89 -68
  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 +9 -2
  46. metadata +43 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 334e5edeb6b74be69160efd1cc960196392fcf985a62b8c710145ede65cd3415
4
- data.tar.gz: fae47eb03c869e02c8fa845ea4e1666e370eff8aa9892921772b0d4ebd7eb119
3
+ metadata.gz: 41420311334e3c3f5bf3c7c0523c10dae50d84ff4788e87c28765a72665a169a
4
+ data.tar.gz: 58f1558f5d6c31c42405772c3ead07bfcc51754ceeff7c6b000f72b868833359
5
5
  SHA512:
6
- metadata.gz: f537bd3debfe5141c04aa4346c2bc4f6eea15f743f3d0bacde99c9b3102d839d8ea58c3195e0b163056b28706cae3351208fc29fbd9e05e906890fe2927cdf39
7
- data.tar.gz: f2a8741d3e3d297dbacc2f974608939c7cd37b22631ad7001a14c7d6b67c4656c875c31442ec100fce1f84936086d72b35b2c330bd33708518e9dbf3539564bc
6
+ metadata.gz: 478782009426a1dab385f9ea8702fed19b7795b3116a5a49b9e9a527374e1fa1b62657f4413aeac7e439f7f2f339e2623d6e2bd9dcf42daefbce43caa4078144
7
+ data.tar.gz: 96195f350fba5187766484f3606016cd245f8cc26c9b1e7083ec11e00b4589cf57ee07d5c8a8097dd56e41c8476a3eaf52ecaa9bf67b5ad333e7a48a268e2992
data/CHANGELOG.md CHANGED
@@ -13,6 +13,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13
13
 
14
14
  ### Removed
15
15
 
16
+ ## [0.6.2] 2022-08-29
17
+ ### Changed
18
+ * `OAuth::Comsumer#options` hash is now handled by `snaky_hash`, which was extracted from `oauth2`
19
+ * symbolized keys, dot-access and snake-case are now normalized
20
+
21
+ ## [0.6.1] 2022-08-23
22
+ ### Changed
23
+ * Fixed documentation in SECURITY.md
24
+ * Change references to master => main
25
+
26
+ ### Added
27
+ * Post install note about v0.6.x EOL approaching in April, 2024
28
+
29
+ ## [0.6.0] 2022-08-23
30
+ ### Added
31
+ * 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.
32
+ * Improved documentation of support policy via Tidelift
33
+ * Stop testing against active_support v2
34
+
35
+ ### Changed
36
+ * Utilize version_gem extracted from oauth2 gem for VERSION
37
+ * Added new `OAuth::Version` namespace
38
+ * VERSION constant now at `OAuth::Version::VERSION`
39
+
40
+ ### Removed
41
+ * Ruby 2.0, 2.1, 2.2, and 2.3 are no longer valid install targets
42
+
16
43
  ## [0.5.14] 2022-08-29
17
44
  The "hopeful last 0.5.x" Release
18
45
 
@@ -35,7 +62,7 @@ The "Typoes are just the worst!" Release
35
62
  The "Is this the last release with a silly name?" Release
36
63
 
37
64
  ### Added
38
- * Post install note about EOL approaching in April, 2023
65
+ * Post install note about v0.5.x EOL approaching in April, 2023
39
66
 
40
67
  ### Changed
41
68
  * Improved documentation
@@ -317,7 +344,7 @@ The "Can it be the end of the line for 0.5.x?" Release
317
344
 
318
345
  ## [0.3.4] 2009-05-06
319
346
  ### Changed
320
- * OAuth::Client::Helper uses OAuth::VERSION (chadisfaction)
347
+ * OAuth::Client::Helper uses OAuth::Version::VERSION (chadisfaction)
321
348
 
322
349
  ### Fixed
323
350
  * Fix OAuth::RequestProxy::ActionControllerRequest's handling of params (Tristan Groléat)
@@ -415,7 +442,10 @@ but please have a look at the unit tests.
415
442
  * Moved all non-Rails functionality from the Rails plugin:
416
443
  http://code.google.com/p/oauth-plugin/
417
444
 
418
- [Unreleased]: https://github.com/oauth-xx/oauth-ruby/compare/v0.5.14...v0.5-maintenance
445
+ [Unreleased]: https://github.com/oauth-xx/oauth-ruby/compare/v0.6.2...v0.6-maintenance
446
+ [0.6.2]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v0.6.2
447
+ [0.6.1]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v0.6.1
448
+ [0.6.0]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v0.6.0
419
449
  [0.5.14]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v0.5.14
420
450
  [0.5.13]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v0.5.13
421
451
  [0.5.12]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v0.5.12
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 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] |
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.14"
335
+ spec.add_dependency "oauth", "~> 0.6.2"
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