oauth 0.5.10 → 0.6.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -2
- data/README.md +60 -55
- data/SECURITY.md +7 -9
- data/bin/oauth +8 -4
- data/lib/oauth/cli/authorize_command.rb +58 -54
- data/lib/oauth/cli/base_command.rb +163 -159
- data/lib/oauth/cli/help_command.rb +9 -5
- data/lib/oauth/cli/query_command.rb +26 -17
- data/lib/oauth/cli/sign_command.rb +58 -52
- data/lib/oauth/cli/version_command.rb +8 -4
- data/lib/oauth/cli.rb +2 -0
- data/lib/oauth/client/action_controller_request.rb +4 -1
- data/lib/oauth/client/em_http.rb +3 -1
- data/lib/oauth/client/helper.rb +76 -72
- data/lib/oauth/client/net_http.rb +111 -104
- data/lib/oauth/client.rb +2 -0
- data/lib/oauth/consumer.rb +50 -32
- data/lib/oauth/errors/error.rb +2 -0
- data/lib/oauth/errors/problem.rb +3 -0
- data/lib/oauth/errors/unauthorized.rb +4 -0
- data/lib/oauth/errors.rb +2 -0
- data/lib/oauth/helper.rb +9 -5
- data/lib/oauth/oauth.rb +4 -2
- data/lib/oauth/oauth_test_helper.rb +2 -0
- data/lib/oauth/request_proxy/base.rb +4 -4
- data/lib/oauth/request_proxy/mock_request.rb +1 -1
- data/lib/oauth/request_proxy/net_http.rb +8 -8
- data/lib/oauth/request_proxy/rest_client_request.rb +4 -3
- data/lib/oauth/request_proxy.rb +4 -1
- data/lib/oauth/server.rb +8 -4
- data/lib/oauth/signature/base.rb +73 -65
- data/lib/oauth/signature/hmac/sha1.rb +15 -9
- data/lib/oauth/signature/hmac/sha256.rb +15 -9
- data/lib/oauth/signature/plaintext.rb +18 -20
- data/lib/oauth/signature/rsa/sha1.rb +46 -38
- data/lib/oauth/signature.rb +3 -0
- data/lib/oauth/token.rb +2 -0
- data/lib/oauth/tokens/access_token.rb +2 -0
- data/lib/oauth/tokens/consumer_token.rb +2 -0
- data/lib/oauth/tokens/request_token.rb +5 -2
- data/lib/oauth/tokens/server_token.rb +2 -0
- data/lib/oauth/tokens/token.rb +2 -0
- data/lib/oauth/version.rb +5 -1
- data/lib/oauth.rb +8 -2
- metadata +45 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bbf3f3a460e4b7cd04184248e8321897a3b6b1e7d7b46803f943fffdd512543
|
4
|
+
data.tar.gz: 6aec1401ce4db1d54b643a11aeab44604a46382151bcd43ba19914fbc0b7d705
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3df8309921280baa7577d3fcc5417c2408cd9b97c90f68ecb871a3ae3d7d42f7374417ca2a4d0002ef3a1a25325d16b7d3cdec52c771e78711e13dcfbd86309c
|
7
|
+
data.tar.gz: 0b36611a495fde3b0ec4116486a0d9122d2ab336681704d5baeebbb7cdd68710b420c98196c84d6ab43940beec662ec6d563dd799bea6117b4c3e58a854d16b3
|
data/CHANGELOG.md
CHANGED
@@ -13,6 +13,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
13
13
|
|
14
14
|
### Removed
|
15
15
|
|
16
|
+
## [0.6.0] 2022-08-23
|
17
|
+
### Added
|
18
|
+
* 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.
|
19
|
+
* Improved documentation of support policy via Tidelift
|
20
|
+
* Stop testing against active_support v2
|
21
|
+
|
22
|
+
### Changed
|
23
|
+
* Utilize version_gem extracted from oauth2 gem for VERSION
|
24
|
+
* Added new `OAuth::Version` namespace
|
25
|
+
* VERSION constant now at `OAuth::Version::VERSION`
|
26
|
+
|
27
|
+
### Removed
|
28
|
+
* Ruby 2.0, 2.1, 2.2, and 2.3 are no longer valid install targets
|
29
|
+
|
16
30
|
## [0.5.10] 2022-05-04
|
17
31
|
The "Can it be the end of the line for 0.5.x?" Release
|
18
32
|
|
@@ -288,7 +302,7 @@ The "Can it be the end of the line for 0.5.x?" Release
|
|
288
302
|
|
289
303
|
## [0.3.4] 2009-05-06
|
290
304
|
### Changed
|
291
|
-
* OAuth::Client::Helper uses OAuth::VERSION (chadisfaction)
|
305
|
+
* OAuth::Client::Helper uses OAuth::Version::VERSION (chadisfaction)
|
292
306
|
|
293
307
|
### Fixed
|
294
308
|
* Fix OAuth::RequestProxy::ActionControllerRequest's handling of params (Tristan Groléat)
|
@@ -386,7 +400,8 @@ but please have a look at the unit tests.
|
|
386
400
|
* Moved all non-Rails functionality from the Rails plugin:
|
387
401
|
http://code.google.com/p/oauth-plugin/
|
388
402
|
|
389
|
-
[Unreleased]: https://github.com/oauth-xx/oauth-ruby/compare/v0.
|
403
|
+
[Unreleased]: https://github.com/oauth-xx/oauth-ruby/compare/v0.6.0...v0.6-maintenance
|
404
|
+
[0.6.0]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v0.6.0
|
390
405
|
[0.5.10]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v0.5.10
|
391
406
|
[0.5.9]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v0.5.9
|
392
407
|
[0.5.8]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v0.5.8
|
data/README.md
CHANGED
@@ -20,10 +20,6 @@ See the sibling `oauth2` gem for OAuth 2.0 implementations in Ruby.
|
|
20
20
|
[oauth1-spec]: http://oauth.net/core/1.0/
|
21
21
|
[sibling-gem]: https://github.com/oauth-xx/oauth-ruby
|
22
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
23
|
## Status
|
28
24
|
|
29
25
|
<!--
|
@@ -57,11 +53,11 @@ appended indicators:
|
|
57
53
|
|:----|-----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
58
54
|
| 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
55
|
| 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️⃣ |
|
56
|
+
| 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] |
|
61
57
|
| 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
58
|
| 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
59
|
| 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]
|
60
|
+
| 7️⃣ | spread 💖 | [![Liberapay Patrons][⛳liberapay-img]][⛳liberapay] [![Sponsor Me][🖇sponsor-img]][🖇sponsor] [![Tweet @ Peter][🏘tweet-img]][🏘tweet] [🌏][aboutme] [👼][angelme] [💻][coderme] |
|
65
61
|
|
66
62
|
<!--
|
67
63
|
The link tokens in the following sections should be kept ordered by the row and badge numbering scheme
|
@@ -124,10 +120,10 @@ The link tokens in the following sections should be kept ordered by the row and
|
|
124
120
|
<!-- 5️⃣ coverage & security -->
|
125
121
|
[⛳cclim-cov]: https://codeclimate.com/github/oauth-xx/oauth-ruby/test_coverage
|
126
122
|
[⛳cclim-cov-img♻️]: https://api.codeclimate.com/v1/badges/3cf23270c21e8791d788/test_coverage
|
127
|
-
[🖇codecov-img♻️]: https://codecov.io/gh/oauth-xx/oauth-ruby/branch/
|
123
|
+
[🖇codecov-img♻️]: https://codecov.io/gh/oauth-xx/oauth-ruby/branch/master/graph/badge.svg?token=4ZNAWNxrf9
|
128
124
|
[🖇codecov]: https://codecov.io/gh/oauth-xx/oauth-ruby
|
129
|
-
[🏘coveralls]: https://coveralls.io/github/oauth-xx/oauth-ruby?branch=
|
130
|
-
[🏘coveralls-img]: https://coveralls.io/repos/github/oauth-xx/oauth-ruby/badge.svg?branch=
|
125
|
+
[🏘coveralls]: https://coveralls.io/github/oauth-xx/oauth-ruby?branch=master
|
126
|
+
[🏘coveralls-img]: https://coveralls.io/repos/github/oauth-xx/oauth-ruby/badge.svg?branch=master
|
131
127
|
[🚎sec-pol]: https://github.com/oauth-xx/oauth-ruby/blob/master/SECURITY.md
|
132
128
|
[🚎sec-pol-img]: https://img.shields.io/badge/security-policy-brightgreen.svg?style=flat
|
133
129
|
[🖐codeQL]: https://github.com/oauth-xx/oauth-ruby/security/code-scanning
|
@@ -158,11 +154,6 @@ The link tokens in the following sections should be kept ordered by the row and
|
|
158
154
|
<!-- Maintainer Contact Links -->
|
159
155
|
[railsbling]: http://www.railsbling.com
|
160
156
|
[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
157
|
|
167
158
|
## Installation
|
168
159
|
|
@@ -190,19 +181,19 @@ For more see [SECURITY.md][🚎sec-pol].
|
|
190
181
|
## Compatibility
|
191
182
|
|
192
183
|
Targeted ruby compatibility is non-EOL versions of Ruby, currently 2.7, 3.0, and
|
193
|
-
3.1. Ruby is limited to 2.
|
194
|
-
|
195
|
-
in accordance with the SemVer spec.
|
184
|
+
3.1. Ruby is limited to 2.4+ in the gemspec, and this will change with minor version bumps,
|
185
|
+
while the gem is still in 0.x, in accordance with the SemVer spec.
|
196
186
|
|
197
|
-
The `master` branch now targets 0.
|
198
|
-
See `v0.
|
187
|
+
The `master` branch now targets 1.0.x releases.
|
188
|
+
See `v0.6-maintenance` branch for Ruby >= 2.4.
|
189
|
+
See `v0.5-maintenance` branch for Ruby >= 2.0.
|
199
190
|
|
200
191
|
NOTE: If there is another 0.5.x release it is anticipated to be the last of the 0.5.x series.
|
201
192
|
|
202
193
|
<details>
|
203
194
|
<summary>Ruby Engine Compatibility Policy</summary>
|
204
195
|
|
205
|
-
This gem is tested against MRI, JRuby, and Truffleruby.
|
196
|
+
This gem is tested against MRI, and to a lesser extent, against JRuby, and Truffleruby.
|
206
197
|
Each of those has varying versions that target a specific version of MRI Ruby.
|
207
198
|
This gem should work in the just-listed Ruby engines according to the targeted MRI compatibility in the table below.
|
208
199
|
If you would like to add support for additional engines,
|
@@ -227,66 +218,82 @@ fashion. If critical issues for a particular implementation exist at the time
|
|
227
218
|
of a major release, support for that Ruby version may be dropped.
|
228
219
|
</details>
|
229
220
|
|
230
|
-
| | Ruby OAuth Version | Maintenance Branch |
|
231
|
-
|
232
|
-
| 1️⃣ | 0.
|
233
|
-
| 2️⃣ | 0.
|
234
|
-
| 3️⃣ |
|
221
|
+
| | Ruby OAuth Version | Maintenance Branch | 🚂 Compatibility | Official 💎 | Unofficial 💎 | Incidental 💎 |
|
222
|
+
|:----|--------------------|--------------------|------------------------|----------------------|------------------------------|---------------|
|
223
|
+
| 1️⃣ | 1.0.x | `master` | Rails 6, 7 | 2.7, 3.0, 3.1 | sorry, not sorry | nope |
|
224
|
+
| 2️⃣ | 0.6.x | `v0.6-maintenance` | Rails 5, 6, 7 | 2.7, 3.0, 3.1 | 2.5, 2.6 | 2.4 |
|
225
|
+
| 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 |
|
226
|
+
| 4️⃣ | older | N/A | | Best of luck to you! | Please upgrade! | noop |
|
235
227
|
|
236
228
|
NOTE: Once 1.0 is released, the 0.x series will only receive critical bug and security updates.
|
237
229
|
See [SECURITY.md][🚎sec-pol]
|
238
230
|
|
231
|
+
🚂 NOTE: See notes on Rails in next section.
|
232
|
+
|
239
233
|
## Basics
|
240
234
|
|
241
235
|
This is a ruby library which is intended to be used in creating Ruby Consumer
|
242
236
|
and Service Provider applications. It is NOT a Rails plugin, but could easily
|
243
237
|
be used for the foundation for such a Rails plugin.
|
244
238
|
|
245
|
-
|
246
|
-
|
247
|
-
|
239
|
+
This gem was originally extracted from @pelle's [oauth-plugin](https://github.com/pelle/oauth-plugin)
|
240
|
+
gem. After extraction that gem was made to depend on this gem.
|
241
|
+
|
242
|
+
Unfortunately, this gem does have some Rails related bits that are
|
243
|
+
**optional** to load. You don't need Rails! The Rails bits may be pulled out
|
244
|
+
into a separate gem after the release of version 1.0 of this gem.
|
248
245
|
|
249
246
|
## Usage
|
250
247
|
|
251
|
-
We need to specify the oauth_callback url explicitly, otherwise it defaults to
|
248
|
+
We need to specify the `oauth_callback` url explicitly, otherwise it defaults to
|
252
249
|
"oob" (Out of Band)
|
253
250
|
|
254
|
-
|
251
|
+
```ruby
|
252
|
+
callback_url = "http://127.0.0.1:3000/oauth/callback"
|
253
|
+
```
|
255
254
|
|
256
255
|
Create a new `OAuth::Consumer` instance by passing it a configuration hash:
|
257
256
|
|
258
|
-
|
257
|
+
```ruby
|
258
|
+
oauth_consumer = OAuth::Consumer.new("key", "secret", site: "https://agree2")
|
259
|
+
```
|
259
260
|
|
260
261
|
Start the process by requesting a token
|
261
262
|
|
262
|
-
|
263
|
+
```ruby
|
264
|
+
request_token = oauth_consumer.get_request_token(oauth_callback: callback_url)
|
263
265
|
|
264
|
-
|
265
|
-
|
266
|
-
|
266
|
+
session[:token] = request_token.token
|
267
|
+
session[:token_secret] = request_token.secret
|
268
|
+
redirect_to request_token.authorize_url(oauth_callback: callback_url)
|
269
|
+
```
|
267
270
|
|
268
271
|
When user returns create an access_token
|
269
272
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
273
|
+
```ruby
|
274
|
+
hash = { oauth_token: session[:token], oauth_token_secret: session[:token_secret] }
|
275
|
+
request_token = OAuth::RequestToken.from_hash(oauth_consumer, hash)
|
276
|
+
access_token = request_token.get_access_token
|
277
|
+
# For 3-legged authorization, flow oauth_verifier is passed as param in callback
|
278
|
+
# access_token = request_token.get_access_token(oauth_verifier: params[:oauth_verifier])
|
279
|
+
@photos = access_token.get("/photos.xml")
|
280
|
+
```
|
276
281
|
|
277
282
|
Now that you have an access token, you can use Typhoeus to interact with the
|
278
283
|
OAuth provider if you choose.
|
279
284
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
285
|
+
```ruby
|
286
|
+
require "typhoeus"
|
287
|
+
require "oauth/request_proxy/typhoeus_request"
|
288
|
+
oauth_params = { consumer: oauth_consumer, token: access_token }
|
289
|
+
hydra = Typhoeus::Hydra.new
|
290
|
+
req = Typhoeus::Request.new(uri, options) # :method needs to be specified in options
|
291
|
+
oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(request_uri: uri))
|
292
|
+
req.options[:headers]["Authorization"] = oauth_helper.header # Signs the request
|
293
|
+
hydra.queue(req)
|
294
|
+
hydra.run
|
295
|
+
@response = req.response
|
296
|
+
```
|
290
297
|
|
291
298
|
## More Information
|
292
299
|
|
@@ -314,13 +321,12 @@ immediately released that restores compatibility. Breaking changes to the public
|
|
314
321
|
major versions. Compatibility with a major and minor versions of Ruby will only be changed with a major version bump.
|
315
322
|
|
316
323
|
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
|
318
|
-
While on 0.x releases three digits of precision should be used.
|
324
|
+
the [Pessimistic Version Constraint][pvc] with two digits of precision.
|
319
325
|
|
320
326
|
For example:
|
321
327
|
|
322
328
|
```ruby
|
323
|
-
spec.add_dependency "oauth", "~> 0.
|
329
|
+
spec.add_dependency "oauth", "~> 0.6.0"
|
324
330
|
```
|
325
331
|
|
326
332
|
## License
|
@@ -364,7 +370,6 @@ Comments are welcome. Contact the [OAuth Ruby mailing list (Google Group)][maili
|
|
364
370
|
[license]: https://github.com/oauth-xx/oauth-ruby/blob/master/LICENSE
|
365
371
|
[license-ref]: https://opensource.org/licenses/MIT
|
366
372
|
[liberapay_donate]: https://liberapay.com/pboling/donate
|
367
|
-
[politicme]: https://nationalprogressiveparty.org
|
368
373
|
[pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint
|
369
374
|
[rubygems]: https://rubygems.org/gems/oauth
|
370
375
|
[security]: https://github.com/oauth-xx/oauth-ruby/blob/master/SECURITY.md
|
data/SECURITY.md
CHANGED
@@ -2,15 +2,13 @@
|
|
2
2
|
|
3
3
|
## Supported Versions
|
4
4
|
|
5
|
-
| Version
|
6
|
-
|
7
|
-
| 0.
|
8
|
-
| 0.
|
9
|
-
| 0.5
|
10
|
-
| <= 0.5 | :x: |
|
5
|
+
| Version | Supported |
|
6
|
+
|--------------------| ------------------ |
|
7
|
+
| 0.6.x (unreleased) | :white_check_mark: |
|
8
|
+
| 0.5.x | :white_check_mark: |
|
9
|
+
| <= 0.5 | :x: |
|
11
10
|
|
12
11
|
## Reporting a Vulnerability
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
[contact]: https://railsbling.com/contact
|
13
|
+
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security).
|
14
|
+
Tidelift will coordinate the fix and disclosure.
|
data/bin/oauth
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
|
4
|
+
require "oauth"
|
4
5
|
require "oauth/cli"
|
5
6
|
|
6
|
-
|
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(
|
15
|
+
OAuth::CLI.new($stdout, $stdin, $stderr, command, ARGV).run
|
@@ -1,69 +1,73 @@
|
|
1
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
3
|
+
module OAuth
|
4
|
+
class CLI
|
5
|
+
class AuthorizeCommand < BaseCommand
|
6
|
+
def required_options
|
7
|
+
[:uri]
|
13
8
|
end
|
14
9
|
|
15
|
-
|
16
|
-
|
10
|
+
def _run
|
11
|
+
request_token = get_request_token
|
17
12
|
|
18
|
-
|
19
|
-
|
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
|
-
|
22
|
-
|
18
|
+
puts "Please visit this url to authorize:"
|
19
|
+
puts request_token.authorize_url
|
23
20
|
|
24
|
-
|
25
|
-
|
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
|
-
|
35
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
57
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
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
|