oauth 1.0.1 → 1.1.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 +11 -1
- data/CONTRIBUTING.md +17 -0
- data/README.md +9 -5
- data/SECURITY.md +1 -0
- data/lib/oauth/request_proxy/base.rb +1 -1
- data/lib/oauth/version.rb +1 -1
- metadata +26 -15
- data/bin/oauth +0 -15
- data/lib/oauth/cli/authorize_command.rb +0 -73
- data/lib/oauth/cli/base_command.rb +0 -214
- data/lib/oauth/cli/help_command.rb +0 -26
- data/lib/oauth/cli/query_command.rb +0 -34
- data/lib/oauth/cli/sign_command.rb +0 -82
- data/lib/oauth/cli/version_command.rb +0 -11
- data/lib/oauth/cli.rb +0 -58
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5ed78104bc98c911e6a9cf2a9e5472eb70a883396346379bcf0ca5ad9a5a5a6a
|
|
4
|
+
data.tar.gz: 918ffe268ffdd0a3e8cb29dda997f07ecef3156c53ff4dde82a68dec5325c8ae
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5ecad352056ded301c816243d846d7628929db7cf10c320ab63627dadc5eb8aa427120f3e74824eb280f8d25e159c639fe16e6405f70d7b02b1ebbf081f0488c
|
|
7
|
+
data.tar.gz: 8cef46c071d1c2bc8e8a3c766477fa90ac76d61661d3131496e20dade1a199a1d9e2248dd41b022383f956f76a987d6579c3960cd4d437f7a143a3043cd086e0
|
data/CHANGELOG.md
CHANGED
|
@@ -13,6 +13,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
13
13
|
|
|
14
14
|
### Removed
|
|
15
15
|
|
|
16
|
+
## [1.1.0] 2022-08-29
|
|
17
|
+
### Changed
|
|
18
|
+
* `OAuth::CLI` has been extracted to a new gem, `oauth-tty`, hosted on [Gitlab](https://gitlab.com/oauth-xx/oauth-tty)
|
|
19
|
+
* The public API of `oauth-tty` is backwards compatible (meaning `OAuth::CLI`)
|
|
20
|
+
* The change within the `oauth` gem is backwards compatible as `oauth-tty` has been added as a dependency
|
|
21
|
+
* Minor version bump is cautionary, as many lines of code have changed.
|
|
22
|
+
* `OAuth::Comsumer#options` hash is now handled by `snaky_hash`, which was extracted from `oauth2`
|
|
23
|
+
* symbolized keys, dot-access and snake-case are now normalized
|
|
24
|
+
|
|
16
25
|
## [1.0.1] 2022-08-29
|
|
17
26
|
### Changed
|
|
18
27
|
* `OAuth::Comsumer#options` hash is now handled by `snaky_hash`, which was extracted from `oauth2`
|
|
@@ -456,7 +465,8 @@ but please have a look at the unit tests.
|
|
|
456
465
|
* Moved all non-Rails functionality from the Rails plugin:
|
|
457
466
|
http://code.google.com/p/oauth-plugin/
|
|
458
467
|
|
|
459
|
-
[Unreleased]: https://github.com/oauth-xx/oauth-ruby/compare/v1.0
|
|
468
|
+
[Unreleased]: https://github.com/oauth-xx/oauth-ruby/compare/v1.1.0...main
|
|
469
|
+
[1.1.0]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v1.1.0
|
|
460
470
|
[1.0.1]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v1.0.1
|
|
461
471
|
[1.0.0]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v1.0.0
|
|
462
472
|
[0.6.2]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v0.6.2
|
data/CONTRIBUTING.md
CHANGED
|
@@ -8,6 +8,23 @@ To submit a patch, please fork the project and create a patch with
|
|
|
8
8
|
tests. Once you're happy with it send a pull request and post a message to the
|
|
9
9
|
[google group][mailinglist].
|
|
10
10
|
|
|
11
|
+
## Run tests
|
|
12
|
+
|
|
13
|
+
### Against Rails 6
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
BUNDLE_GEMFILE=gemfiles/a6.gemfile bundle install
|
|
17
|
+
BUNDLE_GEMFILE=gemfiles/a6.gemfile bundle exec rake
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Against Rails 7
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
BUNDLE_GEMFILE=gemfiles/a7.gemfile bundle install
|
|
25
|
+
BUNDLE_GEMFILE=gemfiles/a7.gemfile bundle exec rake
|
|
26
|
+
```
|
|
27
|
+
|
|
11
28
|
## Contributors
|
|
12
29
|
|
|
13
30
|
[][contributors]
|
data/README.md
CHANGED
|
@@ -22,7 +22,7 @@ See the sibling `oauth2` gem for OAuth 2.0 implementations in Ruby.
|
|
|
22
22
|
|
|
23
23
|
**New EOL Policy**
|
|
24
24
|
|
|
25
|
-
Versions 1.
|
|
25
|
+
Versions 1.x will be EOL no later than April, 2025.
|
|
26
26
|
Versions 0.6.x will be EOL no later than April, 2024.
|
|
27
27
|
Versions 0.5.x will be EOL no later than April, 2023.
|
|
28
28
|
|
|
@@ -30,7 +30,7 @@ This will facilitate dropping support for old, dead, and crusty versions of Ruby
|
|
|
30
30
|
|
|
31
31
|
Non-commercial support for the oldest version of Ruby (which itself is going EOL) will be dropped each year in April.
|
|
32
32
|
|
|
33
|
-
Please upgrade to version 1.
|
|
33
|
+
Please upgrade to version 1.1. The only breaking change in 1.x is dropping old Rubies.
|
|
34
34
|
|
|
35
35
|
## Status
|
|
36
36
|
|
|
@@ -191,7 +191,7 @@ Targeted ruby compatibility is non-EOL versions of Ruby, currently 2.7, 3.0, and
|
|
|
191
191
|
3.1. Ruby is limited to 2.7+ in the gemspec, and this will change with minor version bumps,
|
|
192
192
|
while the gem is still in 0.x, in accordance with the SemVer spec.
|
|
193
193
|
|
|
194
|
-
The `main` branch now targets 1.
|
|
194
|
+
The `main` branch now targets 1.x releases, for Ruby >= 2.7.
|
|
195
195
|
See `v0.6-maintenance` (EOL April, 2024) branch for Ruby >= 2.4.
|
|
196
196
|
See `v0.5-maintenance` (EOL April, 2023) branch for Ruby >= 2.0.
|
|
197
197
|
|
|
@@ -248,7 +248,11 @@ gem. After extraction that gem was made to depend on this gem.
|
|
|
248
248
|
|
|
249
249
|
Unfortunately, this gem does have some Rails related bits that are
|
|
250
250
|
**optional** to load. You don't need Rails! The Rails bits may be pulled out
|
|
251
|
-
into a separate gem with the
|
|
251
|
+
into a separate gem with the 1.x minor updates of this gem.
|
|
252
|
+
|
|
253
|
+
## Extensions
|
|
254
|
+
|
|
255
|
+
* [oauth-tty (on Gitlab)](https://gitlab.com/oauth-xx/oauth-tty) ([rubygems.org](https://rubygems.org/gems/oauth-tty))
|
|
252
256
|
|
|
253
257
|
## Usage
|
|
254
258
|
|
|
@@ -335,7 +339,7 @@ the [Pessimistic Version Constraint][pvc] with two digits of precision.
|
|
|
335
339
|
For example:
|
|
336
340
|
|
|
337
341
|
```ruby
|
|
338
|
-
spec.add_dependency "oauth", "~> 1.
|
|
342
|
+
spec.add_dependency "oauth", "~> 1.1"
|
|
339
343
|
```
|
|
340
344
|
|
|
341
345
|
## License
|
data/SECURITY.md
CHANGED
data/lib/oauth/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: oauth
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Pelle Braendgaard
|
|
@@ -18,6 +18,26 @@ bindir: bin
|
|
|
18
18
|
cert_chain: []
|
|
19
19
|
date: 2022-08-29 00:00:00.000000000 Z
|
|
20
20
|
dependencies:
|
|
21
|
+
- !ruby/object:Gem::Dependency
|
|
22
|
+
name: oauth-tty
|
|
23
|
+
requirement: !ruby/object:Gem::Requirement
|
|
24
|
+
requirements:
|
|
25
|
+
- - "~>"
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
version: '1.0'
|
|
28
|
+
- - ">="
|
|
29
|
+
- !ruby/object:Gem::Version
|
|
30
|
+
version: 1.0.1
|
|
31
|
+
type: :runtime
|
|
32
|
+
prerelease: false
|
|
33
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - "~>"
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '1.0'
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 1.0.1
|
|
21
41
|
- !ruby/object:Gem::Dependency
|
|
22
42
|
name: snaky_hash
|
|
23
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -202,8 +222,7 @@ dependencies:
|
|
|
202
222
|
version: 3.19.0
|
|
203
223
|
description:
|
|
204
224
|
email: oauth-ruby@googlegroups.com
|
|
205
|
-
executables:
|
|
206
|
-
- oauth
|
|
225
|
+
executables: []
|
|
207
226
|
extensions: []
|
|
208
227
|
extra_rdoc_files:
|
|
209
228
|
- TODO
|
|
@@ -215,15 +234,7 @@ files:
|
|
|
215
234
|
- README.md
|
|
216
235
|
- SECURITY.md
|
|
217
236
|
- TODO
|
|
218
|
-
- bin/oauth
|
|
219
237
|
- lib/oauth.rb
|
|
220
|
-
- lib/oauth/cli.rb
|
|
221
|
-
- lib/oauth/cli/authorize_command.rb
|
|
222
|
-
- lib/oauth/cli/base_command.rb
|
|
223
|
-
- lib/oauth/cli/help_command.rb
|
|
224
|
-
- lib/oauth/cli/query_command.rb
|
|
225
|
-
- lib/oauth/cli/sign_command.rb
|
|
226
|
-
- lib/oauth/cli/version_command.rb
|
|
227
238
|
- lib/oauth/client.rb
|
|
228
239
|
- lib/oauth/client/action_controller_request.rb
|
|
229
240
|
- lib/oauth/client/em_http.rb
|
|
@@ -268,15 +279,15 @@ licenses:
|
|
|
268
279
|
- MIT
|
|
269
280
|
metadata:
|
|
270
281
|
homepage_uri: https://github.com/oauth-xx/oauth-ruby
|
|
271
|
-
source_code_uri: https://github.com/oauth-xx/oauth-ruby/tree/v1.0
|
|
272
|
-
changelog_uri: https://github.com/oauth-xx/oauth-ruby/blob/v1.0
|
|
282
|
+
source_code_uri: https://github.com/oauth-xx/oauth-ruby/tree/v1.1.0
|
|
283
|
+
changelog_uri: https://github.com/oauth-xx/oauth-ruby/blob/v1.1.0/CHANGELOG.md
|
|
273
284
|
bug_tracker_uri: https://github.com/oauth-xx/oauth-ruby/issues
|
|
274
|
-
documentation_uri: https://www.rubydoc.info/gems/oauth/1.0
|
|
285
|
+
documentation_uri: https://www.rubydoc.info/gems/oauth/1.1.0
|
|
275
286
|
wiki_uri: https://github.com/oauth-xx/oauth-ruby/wiki
|
|
276
287
|
rubygems_mfa_required: 'true'
|
|
277
288
|
post_install_message: |2
|
|
278
289
|
|
|
279
|
-
You have installed oauth version 1.0
|
|
290
|
+
You have installed oauth version 1.1.0, congratulations!
|
|
280
291
|
|
|
281
292
|
Non-commercial support for the 1.x series will end by April, 2025. Please make a plan to upgrade to the next version prior to that date.
|
|
282
293
|
The only breaking change will be dropped support for Ruby 2.7 and any other versions which will also have reached EOL by then.
|
data/bin/oauth
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require "oauth"
|
|
5
|
-
require "oauth/cli"
|
|
6
|
-
|
|
7
|
-
# don't dump a backtrace on a ^C
|
|
8
|
-
Signal.trap("INT") do
|
|
9
|
-
puts
|
|
10
|
-
exit(1)
|
|
11
|
-
end
|
|
12
|
-
ARGV << "help" if ARGV.empty?
|
|
13
|
-
command = ARGV.shift
|
|
14
|
-
|
|
15
|
-
OAuth::CLI.new($stdout, $stdin, $stderr, command, ARGV).run
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module OAuth
|
|
4
|
-
class CLI
|
|
5
|
-
class AuthorizeCommand < BaseCommand
|
|
6
|
-
def required_options
|
|
7
|
-
[:uri]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def _run
|
|
11
|
-
request_token = get_request_token
|
|
12
|
-
|
|
13
|
-
if request_token.callback_confirmed?
|
|
14
|
-
puts "Server appears to support OAuth 1.0a; enabling support."
|
|
15
|
-
options[:version] = "1.0a"
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
puts "Please visit this url to authorize:"
|
|
19
|
-
puts request_token.authorize_url
|
|
20
|
-
|
|
21
|
-
# parameters for OAuth 1.0a
|
|
22
|
-
oauth_verifier = ask_user_for_verifier
|
|
23
|
-
|
|
24
|
-
verbosely_get_access_token(request_token, oauth_verifier)
|
|
25
|
-
end
|
|
26
|
-
|
|
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
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def verbosely_get_access_token(request_token, oauth_verifier)
|
|
60
|
-
access_token = request_token.get_access_token(oauth_verifier: oauth_verifier)
|
|
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
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module OAuth
|
|
4
|
-
class CLI
|
|
5
|
-
class BaseCommand
|
|
6
|
-
def initialize(stdout, stdin, stderr, arguments)
|
|
7
|
-
@stdout = stdout
|
|
8
|
-
@stdin = stdin
|
|
9
|
-
@stderr = stderr
|
|
10
|
-
|
|
11
|
-
@options = {}
|
|
12
|
-
option_parser.parse!(arguments)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def run
|
|
16
|
-
missing = required_options - options.keys
|
|
17
|
-
if missing.empty?
|
|
18
|
-
_run
|
|
19
|
-
else
|
|
20
|
-
show_missing(missing)
|
|
21
|
-
puts option_parser.help
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def required_options
|
|
26
|
-
[]
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
protected
|
|
30
|
-
|
|
31
|
-
attr_reader :options
|
|
32
|
-
|
|
33
|
-
def show_missing(array)
|
|
34
|
-
array = array.map { |s| "--#{s}" }.join(" ")
|
|
35
|
-
OAuth::CLI.puts_red "Options missing to OAuth CLI: #{array}"
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def xmpp?
|
|
39
|
-
options[:xmpp]
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def verbose?
|
|
43
|
-
options[:verbose]
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def puts(string = nil)
|
|
47
|
-
@stdout.puts(string)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def alert(string = nil)
|
|
51
|
-
@stderr.puts(string)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def parameters
|
|
55
|
-
@parameters ||= begin
|
|
56
|
-
escaped_pairs = options[:params].collect do |pair|
|
|
57
|
-
if /:/.match?(pair)
|
|
58
|
-
Hash[*pair.split(":", 2)].collect do |k, v|
|
|
59
|
-
[CGI.escape(k.strip), CGI.escape(v.strip)].join("=")
|
|
60
|
-
end
|
|
61
|
-
else
|
|
62
|
-
pair
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
querystring = escaped_pairs * "&"
|
|
67
|
-
cli_params = CGI.parse(querystring)
|
|
68
|
-
|
|
69
|
-
{
|
|
70
|
-
"oauth_consumer_key" => options[:oauth_consumer_key],
|
|
71
|
-
"oauth_nonce" => options[:oauth_nonce],
|
|
72
|
-
"oauth_timestamp" => options[:oauth_timestamp],
|
|
73
|
-
"oauth_token" => options[:oauth_token],
|
|
74
|
-
"oauth_signature_method" => options[:oauth_signature_method],
|
|
75
|
-
"oauth_version" => options[:oauth_version]
|
|
76
|
-
}.reject { |_k, v| v.nil? || v == "" }.merge(cli_params)
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def option_parser
|
|
81
|
-
@option_parser ||= OptionParser.new do |opts|
|
|
82
|
-
opts.banner = "Usage: oauth <command> [ARGS]"
|
|
83
|
-
|
|
84
|
-
_option_parser_defaults
|
|
85
|
-
_option_parser_common(opts)
|
|
86
|
-
_option_parser_sign_and_query(opts)
|
|
87
|
-
_option_parser_authorization(opts)
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def _option_parser_defaults
|
|
92
|
-
options[:oauth_nonce] = OAuth::Helper.generate_key
|
|
93
|
-
options[:oauth_signature_method] = "HMAC-SHA1"
|
|
94
|
-
options[:oauth_timestamp] = OAuth::Helper.generate_timestamp
|
|
95
|
-
options[:oauth_version] = "1.0"
|
|
96
|
-
options[:method] = :post
|
|
97
|
-
options[:params] = []
|
|
98
|
-
options[:scheme] = :header
|
|
99
|
-
options[:version] = "1.0"
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def _option_parser_common(opts)
|
|
103
|
-
## Common Options
|
|
104
|
-
|
|
105
|
-
opts.on("-B", "--body", "Use the request body for OAuth parameters.") do
|
|
106
|
-
options[:scheme] = :body
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
opts.on("--consumer-key KEY", "Specifies the consumer key to use.") do |v|
|
|
110
|
-
options[:oauth_consumer_key] = v
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
opts.on("--consumer-secret SECRET", "Specifies the consumer secret to use.") do |v|
|
|
114
|
-
options[:oauth_consumer_secret] = v
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
opts.on("-H", "--header", "Use the 'Authorization' header for OAuth parameters (default).") do
|
|
118
|
-
options[:scheme] = :header
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
opts.on("-Q", "--query-string", "Use the query string for OAuth parameters.") do
|
|
122
|
-
options[:scheme] = :query_string
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
opts.on("-O", "--options FILE", "Read options from a file") do |v|
|
|
126
|
-
arguments = open(v).readlines.map { |l| l.chomp.split }.flatten
|
|
127
|
-
options2 = parse_options(arguments)
|
|
128
|
-
options.merge!(options2)
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
def _option_parser_sign_and_query(opts)
|
|
133
|
-
opts.separator("\n options for signing and querying")
|
|
134
|
-
|
|
135
|
-
opts.on("--method METHOD", "Specifies the method (e.g. GET) to use when signing.") do |v|
|
|
136
|
-
options[:method] = v
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
opts.on("--nonce NONCE", "Specifies the nonce to use.") do |v|
|
|
140
|
-
options[:oauth_nonce] = v
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
opts.on("--parameters PARAMS", "Specifies the parameters to use when signing.") do |v|
|
|
144
|
-
options[:params] << v
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
opts.on("--signature-method METHOD", "Specifies the signature method to use; defaults to HMAC-SHA1.") do |v|
|
|
148
|
-
options[:oauth_signature_method] = v
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
opts.on("--token TOKEN", "Specifies the token to use.") do |v|
|
|
152
|
-
options[:oauth_token] = v
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
opts.on("--secret SECRET", "Specifies the token secret to use.") do |v|
|
|
156
|
-
options[:oauth_token_secret] = v
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
opts.on("--timestamp TIMESTAMP", "Specifies the timestamp to use.") do |v|
|
|
160
|
-
options[:oauth_timestamp] = v
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
opts.on("--realm REALM", "Specifies the realm to use.") do |v|
|
|
164
|
-
options[:realm] = v
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
opts.on("--uri URI", "Specifies the URI to use when signing.") do |v|
|
|
168
|
-
options[:uri] = v
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
opts.on("--version [VERSION]", "Specifies the OAuth version to use.") do |v|
|
|
172
|
-
options[:oauth_version] = v
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
opts.on("--no-version", "Omit oauth_version.") do
|
|
176
|
-
options[:oauth_version] = nil
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
opts.on("--xmpp", "Generate XMPP stanzas.") do
|
|
180
|
-
options[:xmpp] = true
|
|
181
|
-
options[:method] ||= "iq"
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
opts.on("-v", "--verbose", "Be verbose.") do
|
|
185
|
-
options[:verbose] = true
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
def _option_parser_authorization(opts)
|
|
190
|
-
opts.separator("\n options for authorization")
|
|
191
|
-
|
|
192
|
-
opts.on("--access-token-url URL", "Specifies the access token URL.") do |v|
|
|
193
|
-
options[:access_token_url] = v
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
opts.on("--authorize-url URL", "Specifies the authorization URL.") do |v|
|
|
197
|
-
options[:authorize_url] = v
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
opts.on("--callback-url URL", "Specifies a callback URL.") do |v|
|
|
201
|
-
options[:oauth_callback] = v
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
opts.on("--request-token-url URL", "Specifies the request token URL.") do |v|
|
|
205
|
-
options[:request_token_url] = v
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
opts.on("--scope SCOPE", "Specifies the scope (Google-specific).") do |v|
|
|
209
|
-
options[:scope] = v
|
|
210
|
-
end
|
|
211
|
-
end
|
|
212
|
-
end
|
|
213
|
-
end
|
|
214
|
-
end
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module OAuth
|
|
4
|
-
class CLI
|
|
5
|
-
class HelpCommand < BaseCommand
|
|
6
|
-
def run
|
|
7
|
-
puts <<-EOT
|
|
8
|
-
Usage: oauth COMMAND [ARGS]
|
|
9
|
-
|
|
10
|
-
Available oauth commands are:
|
|
11
|
-
a, authorize Obtain an access token and secret for a user
|
|
12
|
-
q, query Query a protected resource
|
|
13
|
-
s, sign Generate an OAuth signature
|
|
14
|
-
|
|
15
|
-
In addition to those, there are:
|
|
16
|
-
v, version Displays the current version of the library (or --version, -v)
|
|
17
|
-
h, help Displays this help (or --help, -h)
|
|
18
|
-
|
|
19
|
-
Tip: All commands can be run without args for specific help.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
EOT
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module OAuth
|
|
4
|
-
class CLI
|
|
5
|
-
class QueryCommand < BaseCommand
|
|
6
|
-
extend OAuth::Helper
|
|
7
|
-
|
|
8
|
-
def required_options
|
|
9
|
-
%i[oauth_consumer_key oauth_consumer_secret oauth_token oauth_token_secret]
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def _run
|
|
13
|
-
consumer = OAuth::Consumer.new(options[:oauth_consumer_key], options[:oauth_consumer_secret],
|
|
14
|
-
scheme: options[:scheme])
|
|
15
|
-
|
|
16
|
-
access_token = OAuth::AccessToken.new(consumer, options[:oauth_token], options[:oauth_token_secret])
|
|
17
|
-
|
|
18
|
-
# append params to the URL
|
|
19
|
-
uri = URI.parse(options[:uri])
|
|
20
|
-
params = parameters.map do |k, v|
|
|
21
|
-
Array(v).map do |v2|
|
|
22
|
-
"#{OAuth::Helper.escape(k)}=#{OAuth::Helper.escape(v2)}"
|
|
23
|
-
end * "&"
|
|
24
|
-
end
|
|
25
|
-
uri.query = [uri.query, *params].compact * "&"
|
|
26
|
-
puts uri.to_s
|
|
27
|
-
|
|
28
|
-
response = access_token.request(options[:method].to_s.downcase.to_sym, uri.to_s)
|
|
29
|
-
puts "#{response.code} #{response.message}"
|
|
30
|
-
puts response.body
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module OAuth
|
|
4
|
-
class CLI
|
|
5
|
-
class SignCommand < BaseCommand
|
|
6
|
-
def required_options
|
|
7
|
-
%i[oauth_consumer_key oauth_consumer_secret oauth_token oauth_token_secret]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def _run
|
|
11
|
-
request = OAuth::RequestProxy.proxy \
|
|
12
|
-
"method" => options[:method],
|
|
13
|
-
"uri" => options[:uri],
|
|
14
|
-
"parameters" => parameters
|
|
15
|
-
|
|
16
|
-
puts_verbose_parameters(request) if verbose?
|
|
17
|
-
|
|
18
|
-
request.sign! \
|
|
19
|
-
consumer_secret: options[:oauth_consumer_secret],
|
|
20
|
-
token_secret: options[:oauth_token_secret]
|
|
21
|
-
|
|
22
|
-
if verbose?
|
|
23
|
-
puts_verbose_request(request)
|
|
24
|
-
else
|
|
25
|
-
puts request.oauth_signature
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def puts_verbose_parameters(request)
|
|
30
|
-
puts "OAuth parameters:"
|
|
31
|
-
request.oauth_parameters.each do |k, v|
|
|
32
|
-
puts " #{[k, v].join(": ")}"
|
|
33
|
-
end
|
|
34
|
-
puts
|
|
35
|
-
|
|
36
|
-
if request.non_oauth_parameters.any?
|
|
37
|
-
puts "Parameters:"
|
|
38
|
-
request.non_oauth_parameters.each do |k, v|
|
|
39
|
-
puts " #{[k, v].join(": ")}"
|
|
40
|
-
end
|
|
41
|
-
puts
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def puts_verbose_request(request)
|
|
46
|
-
puts "Method: #{request.method}"
|
|
47
|
-
puts "URI: #{request.uri}"
|
|
48
|
-
puts "Normalized params: #{request.normalized_parameters}" unless options[:xmpp]
|
|
49
|
-
puts "Signature base string: #{request.signature_base_string}"
|
|
50
|
-
|
|
51
|
-
if xmpp?
|
|
52
|
-
puts
|
|
53
|
-
puts "XMPP Stanza:"
|
|
54
|
-
puts xmpp_output(request)
|
|
55
|
-
puts
|
|
56
|
-
puts "Note: You may want to use bare JIDs in your URI."
|
|
57
|
-
puts
|
|
58
|
-
else
|
|
59
|
-
puts "OAuth Request URI: #{request.signed_uri}"
|
|
60
|
-
puts "Request URI: #{request.signed_uri(with_oauth: false)}"
|
|
61
|
-
puts "Authorization header: #{request.oauth_header(realm: options[:realm])}"
|
|
62
|
-
end
|
|
63
|
-
puts "Signature: #{request.oauth_signature}"
|
|
64
|
-
puts "Escaped signature: #{OAuth::Helper.escape(request.oauth_signature)}"
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def xmpp_output(request)
|
|
68
|
-
<<-EOS
|
|
69
|
-
<oauth xmlns='urn:xmpp:oauth:0'>
|
|
70
|
-
<oauth_consumer_key>#{request.oauth_consumer_key}</oauth_consumer_key>
|
|
71
|
-
<oauth_token>#{request.oauth_token}</oauth_token>
|
|
72
|
-
<oauth_signature_method>#{request.oauth_signature_method}</oauth_signature_method>
|
|
73
|
-
<oauth_signature>#{request.oauth_signature}</oauth_signature>
|
|
74
|
-
<oauth_timestamp>#{request.oauth_timestamp}</oauth_timestamp>
|
|
75
|
-
<oauth_nonce>#{request.oauth_nonce}</oauth_nonce>
|
|
76
|
-
<oauth_version>#{request.oauth_version}</oauth_version>
|
|
77
|
-
</oauth>
|
|
78
|
-
EOS
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
data/lib/oauth/cli.rb
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "optparse"
|
|
4
|
-
require "oauth/cli/base_command"
|
|
5
|
-
require "oauth/cli/help_command"
|
|
6
|
-
require "oauth/cli/query_command"
|
|
7
|
-
require "oauth/cli/authorize_command"
|
|
8
|
-
require "oauth/cli/sign_command"
|
|
9
|
-
require "oauth/cli/version_command"
|
|
10
|
-
require "active_support/core_ext/string/inflections"
|
|
11
|
-
|
|
12
|
-
module OAuth
|
|
13
|
-
class CLI
|
|
14
|
-
def self.puts_red(string)
|
|
15
|
-
puts "\033[0;91m#{string}\033[0m"
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
ALIASES = {
|
|
19
|
-
"h" => "help",
|
|
20
|
-
"v" => "version",
|
|
21
|
-
"q" => "query",
|
|
22
|
-
"a" => "authorize",
|
|
23
|
-
"s" => "sign"
|
|
24
|
-
}.freeze
|
|
25
|
-
|
|
26
|
-
def initialize(stdout, stdin, stderr, command, arguments)
|
|
27
|
-
klass = get_command_class(parse_command(command))
|
|
28
|
-
@command = klass.new(stdout, stdin, stderr, arguments)
|
|
29
|
-
@help_command = HelpCommand.new(stdout, stdin, stderr, [])
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def run
|
|
33
|
-
@command.run
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
private
|
|
37
|
-
|
|
38
|
-
def get_command_class(command)
|
|
39
|
-
Object.const_get("OAuth::CLI::#{command.camelize}Command")
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def parse_command(command)
|
|
43
|
-
case command = command.to_s.downcase
|
|
44
|
-
when "--version", "-v"
|
|
45
|
-
"version"
|
|
46
|
-
when "--help", "-h", nil, ""
|
|
47
|
-
"help"
|
|
48
|
-
when *ALIASES.keys
|
|
49
|
-
ALIASES[command]
|
|
50
|
-
when *ALIASES.values
|
|
51
|
-
command
|
|
52
|
-
else
|
|
53
|
-
OAuth::CLI.puts_red "Command '#{command}' not found"
|
|
54
|
-
"help"
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|