oauth 1.0.1 → 1.1.1

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 (47) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +4 -0
  3. data/CHANGELOG.md +325 -39
  4. data/CITATION.cff +20 -0
  5. data/CODE_OF_CONDUCT.md +79 -29
  6. data/CONTRIBUTING.md +221 -15
  7. data/FUNDING.md +77 -0
  8. data/{LICENSE → LICENSE.txt} +1 -1
  9. data/README.md +546 -274
  10. data/REEK +0 -0
  11. data/RUBOCOP.md +71 -0
  12. data/SECURITY.md +27 -10
  13. data/lib/oauth/client/action_controller_request.rb +14 -9
  14. data/lib/oauth/client/em_http.rb +106 -99
  15. data/lib/oauth/client/helper.rb +15 -11
  16. data/lib/oauth/client/net_http.rb +39 -13
  17. data/lib/oauth/consumer.rb +105 -54
  18. data/lib/oauth/errors/problem.rb +1 -1
  19. data/lib/oauth/helper.rb +25 -3
  20. data/lib/oauth/oauth.rb +28 -6
  21. data/lib/oauth/optional.rb +20 -0
  22. data/lib/oauth/request_proxy/action_controller_request.rb +11 -7
  23. data/lib/oauth/request_proxy/action_dispatch_request.rb +41 -0
  24. data/lib/oauth/request_proxy/base.rb +16 -13
  25. data/lib/oauth/request_proxy/em_http_request.rb +53 -52
  26. data/lib/oauth/request_proxy/jabber_request.rb +9 -2
  27. data/lib/oauth/request_proxy/net_http.rb +1 -1
  28. data/lib/oauth/request_proxy/rest_client_request.rb +4 -3
  29. data/lib/oauth/server.rb +12 -8
  30. data/lib/oauth/signature/base.rb +1 -1
  31. data/lib/oauth/signature/rsa/sha1.rb +11 -4
  32. data/lib/oauth/tokens/access_token.rb +1 -1
  33. data/lib/oauth/tokens/consumer_token.rb +2 -2
  34. data/lib/oauth/tokens/request_token.rb +9 -4
  35. data/lib/oauth/version.rb +1 -1
  36. data.tar.gz.sig +0 -0
  37. metadata +265 -89
  38. metadata.gz.sig +3 -0
  39. data/TODO +0 -32
  40. data/bin/oauth +0 -15
  41. data/lib/oauth/cli/authorize_command.rb +0 -73
  42. data/lib/oauth/cli/base_command.rb +0 -214
  43. data/lib/oauth/cli/help_command.rb +0 -26
  44. data/lib/oauth/cli/query_command.rb +0 -34
  45. data/lib/oauth/cli/sign_command.rb +0 -82
  46. data/lib/oauth/cli/version_command.rb +0 -11
  47. data/lib/oauth/cli.rb +0 -58
@@ -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
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OAuth
4
- class CLI
5
- class VersionCommand < BaseCommand
6
- def run
7
- puts "OAuth Gem #{OAuth::Version::VERSION}"
8
- end
9
- end
10
- end
11
- 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