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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -3
- data/README.md +56 -46
- data/SECURITY.md +0 -2
- 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 +89 -68
- 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 +9 -2
- metadata +43 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41420311334e3c3f5bf3c7c0523c10dae50d84ff4788e87c28765a72665a169a
|
4
|
+
data.tar.gz: 58f1558f5d6c31c42405772c3ead07bfcc51754ceeff7c6b000f72b868833359
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
26
|
-
The v0.
|
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.
|
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 `
|
193
|
-
See `v0.
|
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
|
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 💎
|
226
|
-
|
227
|
-
| 1️⃣ | 1.0.x | `main` | Rails 6, 7 | 2.7, 3.0, 3.1 | sorry, not sorry
|
228
|
-
| 2️⃣ | 0.6.x | `v0.6-maintenance` | Rails 5, 6, 7 | 2.7, 3.0, 3.1 | 2.5, 2.6
|
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
|
230
|
-
| 4️⃣ | older | N/A | | Best of luck to you! | Please upgrade!
|
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
|
-
|
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
|
-
|
269
|
+
```ruby
|
270
|
+
request_token = oauth_consumer.get_request_token(oauth_callback: callback_url)
|
265
271
|
|
266
|
-
|
267
|
-
|
268
|
-
|
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
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
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
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
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
|
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.
|
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
|
-
|
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
|