oauth 0.5.14 → 1.1.6

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 (69) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +1 -0
  3. data/CHANGELOG.md +663 -239
  4. data/CITATION.cff +20 -0
  5. data/CODE_OF_CONDUCT.md +79 -29
  6. data/CONTRIBUTING.md +264 -15
  7. data/FUNDING.md +74 -0
  8. data/LICENSE.md +71 -0
  9. data/README.md +642 -297
  10. data/RUBOCOP.md +71 -0
  11. data/SECURITY.md +11 -12
  12. data/certs/pboling.pem +27 -0
  13. data/lib/oauth/auth_sanitizer.rb +36 -0
  14. data/lib/oauth/client/action_controller_request.rb +24 -12
  15. data/lib/oauth/client/em_http.rb +107 -100
  16. data/lib/oauth/client/helper.rb +80 -72
  17. data/lib/oauth/client/net_http.rb +139 -106
  18. data/lib/oauth/client.rb +2 -0
  19. data/lib/oauth/consumer.rb +250 -118
  20. data/lib/oauth/errors/error.rb +2 -0
  21. data/lib/oauth/errors/problem.rb +4 -1
  22. data/lib/oauth/errors/unauthorized.rb +4 -0
  23. data/lib/oauth/errors.rb +2 -0
  24. data/lib/oauth/helper.rb +34 -8
  25. data/lib/oauth/oauth.rb +32 -8
  26. data/lib/oauth/oauth_test_helper.rb +2 -0
  27. data/lib/oauth/optional.rb +20 -0
  28. data/lib/oauth/request_proxy/action_controller_request.rb +14 -31
  29. data/lib/oauth/request_proxy/action_dispatch_request.rb +34 -0
  30. data/lib/oauth/request_proxy/base.rb +42 -31
  31. data/lib/oauth/request_proxy/em_http_request.rb +53 -52
  32. data/lib/oauth/request_proxy/jabber_request.rb +9 -2
  33. data/lib/oauth/request_proxy/mock_request.rb +1 -1
  34. data/lib/oauth/request_proxy/net_http.rb +6 -8
  35. data/lib/oauth/request_proxy/rack_request.rb +0 -4
  36. data/lib/oauth/request_proxy/rest_client_request.rb +6 -4
  37. data/lib/oauth/request_proxy.rb +20 -13
  38. data/lib/oauth/server.rb +14 -6
  39. data/lib/oauth/signature/base.rb +82 -66
  40. data/lib/oauth/signature/hmac/sha1.rb +15 -9
  41. data/lib/oauth/signature/hmac/sha256.rb +15 -9
  42. data/lib/oauth/signature/plaintext.rb +18 -20
  43. data/lib/oauth/signature/rsa/sha1.rb +53 -38
  44. data/lib/oauth/signature.rb +40 -33
  45. data/lib/oauth/token.rb +2 -0
  46. data/lib/oauth/tokens/access_token.rb +3 -1
  47. data/lib/oauth/tokens/consumer_token.rb +10 -6
  48. data/lib/oauth/tokens/request_token.rb +12 -4
  49. data/lib/oauth/tokens/server_token.rb +2 -0
  50. data/lib/oauth/tokens/token.rb +15 -1
  51. data/lib/oauth/version.rb +6 -1
  52. data/lib/oauth.rb +11 -2
  53. data/sig/oauth/consumer.rbs +9 -0
  54. data/sig/oauth/signature/base.rbs +12 -0
  55. data/sig/oauth/tokens/token.rbs +8 -0
  56. data/sig/oauth/version.rbs +6 -0
  57. data.tar.gz.sig +0 -0
  58. metadata +349 -90
  59. metadata.gz.sig +0 -0
  60. data/LICENSE +0 -21
  61. data/TODO +0 -32
  62. data/bin/oauth +0 -11
  63. data/lib/oauth/cli/authorize_command.rb +0 -69
  64. data/lib/oauth/cli/base_command.rb +0 -210
  65. data/lib/oauth/cli/help_command.rb +0 -22
  66. data/lib/oauth/cli/query_command.rb +0 -25
  67. data/lib/oauth/cli/sign_command.rb +0 -78
  68. data/lib/oauth/cli/version_command.rb +0 -7
  69. data/lib/oauth/cli.rb +0 -56
@@ -1,69 +0,0 @@
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
9
-
10
- if request_token.callback_confirmed?
11
- puts "Server appears to support OAuth 1.0a; enabling support."
12
- options[:version] = "1.0a"
13
- end
14
-
15
- puts "Please visit this url to authorize:"
16
- puts request_token.authorize_url
17
-
18
- # parameters for OAuth 1.0a
19
- oauth_verifier = ask_user_for_verifier
20
-
21
- verbosely_get_access_token(request_token, oauth_verifier)
22
- end
23
-
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
33
-
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
44
-
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
53
- end
54
- end
55
-
56
- def verbosely_get_access_token(request_token, oauth_verifier)
57
- access_token = request_token.get_access_token(oauth_verifier: oauth_verifier)
58
-
59
- puts "Response:"
60
- access_token.params.each do |k, v|
61
- puts " #{k}: #{v}" unless k.is_a?(Symbol)
62
- 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
- end
68
- end
69
- end
@@ -1,210 +0,0 @@
1
- class OAuth::CLI
2
- class BaseCommand
3
- def initialize(stdout, stdin, stderr, arguments)
4
- @stdout = stdout
5
- @stdin = stdin
6
- @stderr = stderr
7
-
8
- @options = {}
9
- option_parser.parse!(arguments)
10
- end
11
-
12
- def run
13
- missing = required_options - options.keys
14
- if missing.empty?
15
- _run
16
- else
17
- show_missing(missing)
18
- puts option_parser.help
19
- end
20
- end
21
-
22
- def required_options
23
- []
24
- end
25
-
26
- protected
27
-
28
- attr_reader :options
29
-
30
- def show_missing(array)
31
- array = array.map { |s| "--#{s}" }.join(" ")
32
- OAuth::CLI.puts_red "Options missing to OAuth CLI: #{array}"
33
- end
34
-
35
- def xmpp?
36
- options[:xmpp]
37
- end
38
-
39
- def verbose?
40
- options[:verbose]
41
- end
42
-
43
- def puts(string = nil)
44
- @stdout.puts(string)
45
- end
46
-
47
- def alert(string = nil)
48
- @stderr.puts(string)
49
- end
50
-
51
- def parameters
52
- @parameters ||= begin
53
- escaped_pairs = options[:params].collect do |pair|
54
- if pair =~ /:/
55
- Hash[*pair.split(":", 2)].collect do |k, v|
56
- [CGI.escape(k.strip), CGI.escape(v.strip)].join("=")
57
- end
58
- else
59
- pair
60
- end
61
- end
62
-
63
- querystring = escaped_pairs * "&"
64
- cli_params = CGI.parse(querystring)
65
-
66
- {
67
- "oauth_consumer_key" => options[:oauth_consumer_key],
68
- "oauth_nonce" => options[:oauth_nonce],
69
- "oauth_timestamp" => options[:oauth_timestamp],
70
- "oauth_token" => options[:oauth_token],
71
- "oauth_signature_method" => options[:oauth_signature_method],
72
- "oauth_version" => options[:oauth_version]
73
- }.reject { |_k, v| v.nil? || v == "" }.merge(cli_params)
74
- end
75
- end
76
-
77
- def option_parser
78
- @option_parser ||= OptionParser.new do |opts|
79
- opts.banner = "Usage: oauth <command> [ARGS]"
80
-
81
- _option_parser_defaults
82
- _option_parser_common(opts)
83
- _option_parser_sign_and_query(opts)
84
- _option_parser_authorization(opts)
85
- end
86
- end
87
-
88
- def _option_parser_defaults
89
- options[:oauth_nonce] = OAuth::Helper.generate_key
90
- options[:oauth_signature_method] = "HMAC-SHA1"
91
- options[:oauth_timestamp] = OAuth::Helper.generate_timestamp
92
- options[:oauth_version] = "1.0"
93
- options[:method] = :post
94
- options[:params] = []
95
- options[:scheme] = :header
96
- options[:version] = "1.0"
97
- end
98
-
99
- def _option_parser_common(opts)
100
- ## Common Options
101
-
102
- opts.on("-B", "--body", "Use the request body for OAuth parameters.") do
103
- options[:scheme] = :body
104
- end
105
-
106
- opts.on("--consumer-key KEY", "Specifies the consumer key to use.") do |v|
107
- options[:oauth_consumer_key] = v
108
- end
109
-
110
- opts.on("--consumer-secret SECRET", "Specifies the consumer secret to use.") do |v|
111
- options[:oauth_consumer_secret] = v
112
- end
113
-
114
- opts.on("-H", "--header", "Use the 'Authorization' header for OAuth parameters (default).") do
115
- options[:scheme] = :header
116
- end
117
-
118
- opts.on("-Q", "--query-string", "Use the query string for OAuth parameters.") do
119
- options[:scheme] = :query_string
120
- end
121
-
122
- opts.on("-O", "--options FILE", "Read options from a file") do |v|
123
- arguments = open(v).readlines.map { |l| l.chomp.split(" ") }.flatten
124
- options2 = parse_options(arguments)
125
- options.merge!(options2)
126
- end
127
- end
128
-
129
- def _option_parser_sign_and_query(opts)
130
- opts.separator("\n options for signing and querying")
131
-
132
- opts.on("--method METHOD", "Specifies the method (e.g. GET) to use when signing.") do |v|
133
- options[:method] = v
134
- end
135
-
136
- opts.on("--nonce NONCE", "Specifies the nonce to use.") do |v|
137
- options[:oauth_nonce] = v
138
- end
139
-
140
- opts.on("--parameters PARAMS", "Specifies the parameters to use when signing.") do |v|
141
- options[:params] << v
142
- end
143
-
144
- opts.on("--signature-method METHOD", "Specifies the signature method to use; defaults to HMAC-SHA1.") do |v|
145
- options[:oauth_signature_method] = v
146
- end
147
-
148
- opts.on("--token TOKEN", "Specifies the token to use.") do |v|
149
- options[:oauth_token] = v
150
- end
151
-
152
- opts.on("--secret SECRET", "Specifies the token secret to use.") do |v|
153
- options[:oauth_token_secret] = v
154
- end
155
-
156
- opts.on("--timestamp TIMESTAMP", "Specifies the timestamp to use.") do |v|
157
- options[:oauth_timestamp] = v
158
- end
159
-
160
- opts.on("--realm REALM", "Specifies the realm to use.") do |v|
161
- options[:realm] = v
162
- end
163
-
164
- opts.on("--uri URI", "Specifies the URI to use when signing.") do |v|
165
- options[:uri] = v
166
- end
167
-
168
- opts.on("--version [VERSION]", "Specifies the OAuth version to use.") do |v|
169
- options[:oauth_version] = v
170
- end
171
-
172
- opts.on("--no-version", "Omit oauth_version.") do
173
- options[:oauth_version] = nil
174
- end
175
-
176
- opts.on("--xmpp", "Generate XMPP stanzas.") do
177
- options[:xmpp] = true
178
- options[:method] ||= "iq"
179
- end
180
-
181
- opts.on("-v", "--verbose", "Be verbose.") do
182
- options[:verbose] = true
183
- end
184
- end
185
-
186
- def _option_parser_authorization(opts)
187
- opts.separator("\n options for authorization")
188
-
189
- opts.on("--access-token-url URL", "Specifies the access token URL.") do |v|
190
- options[:access_token_url] = v
191
- end
192
-
193
- opts.on("--authorize-url URL", "Specifies the authorization URL.") do |v|
194
- options[:authorize_url] = v
195
- end
196
-
197
- opts.on("--callback-url URL", "Specifies a callback URL.") do |v|
198
- options[:oauth_callback] = v
199
- end
200
-
201
- opts.on("--request-token-url URL", "Specifies the request token URL.") do |v|
202
- options[:request_token_url] = v
203
- end
204
-
205
- opts.on("--scope SCOPE", "Specifies the scope (Google-specific).") do |v|
206
- options[:scope] = v
207
- end
208
- end
209
- end
210
- end
@@ -1,22 +0,0 @@
1
- class OAuth::CLI
2
- class HelpCommand < BaseCommand
3
- def run
4
- puts <<-EOT
5
- Usage: oauth COMMAND [ARGS]
6
-
7
- Available oauth commands are:
8
- a, authorize Obtain an access token and secret for a user
9
- q, query Query a protected resource
10
- s, sign Generate an OAuth signature
11
-
12
- In addition to those, there are:
13
- v, version Displays the current version of the library (or --version, -v)
14
- h, help Displays this help (or --help, -h)
15
-
16
- Tip: All commands can be run without args for specific help.
17
-
18
-
19
- EOT
20
- end
21
- end
22
- end
@@ -1,25 +0,0 @@
1
- class OAuth::CLI
2
- class QueryCommand < BaseCommand
3
- extend OAuth::Helper
4
-
5
- def required_options
6
- %i[oauth_consumer_key oauth_consumer_secret oauth_token oauth_token_secret]
7
- end
8
-
9
- def _run
10
- consumer = OAuth::Consumer.new(options[:oauth_consumer_key], options[:oauth_consumer_secret], scheme: options[:scheme])
11
-
12
- access_token = OAuth::AccessToken.new(consumer, options[:oauth_token], options[:oauth_token_secret])
13
-
14
- # append params to the URL
15
- uri = URI.parse(options[:uri])
16
- params = parameters.map { |k, v| Array(v).map { |v2| "#{OAuth::Helper.escape(k)}=#{OAuth::Helper.escape(v2)}" } * "&" }
17
- uri.query = [uri.query, *params].reject(&:nil?) * "&"
18
- puts uri.to_s
19
-
20
- response = access_token.request(options[:method].to_s.downcase.to_sym, uri.to_s)
21
- puts "#{response.code} #{response.message}"
22
- puts response.body
23
- end
24
- end
25
- end
@@ -1,78 +0,0 @@
1
- class OAuth::CLI
2
- class SignCommand < BaseCommand
3
- def required_options
4
- %i[oauth_consumer_key oauth_consumer_secret oauth_token oauth_token_secret]
5
- end
6
-
7
- def _run
8
- request = OAuth::RequestProxy.proxy \
9
- "method" => options[:method],
10
- "uri" => options[:uri],
11
- "parameters" => parameters
12
-
13
- puts_verbose_parameters(request) if verbose?
14
-
15
- request.sign! \
16
- consumer_secret: options[:oauth_consumer_secret],
17
- token_secret: options[:oauth_token_secret]
18
-
19
- if verbose?
20
- puts_verbose_request(request)
21
- else
22
- puts request.oauth_signature
23
- end
24
- end
25
-
26
- def puts_verbose_parameters(request)
27
- puts "OAuth parameters:"
28
- request.oauth_parameters.each do |k, v|
29
- puts " " + [k, v].join(": ")
30
- end
31
- puts
32
-
33
- if request.non_oauth_parameters.any?
34
- puts "Parameters:"
35
- request.non_oauth_parameters.each do |k, v|
36
- puts " " + [k, v].join(": ")
37
- end
38
- puts
39
- end
40
- end
41
-
42
- def puts_verbose_request(request)
43
- puts "Method: #{request.method}"
44
- puts "URI: #{request.uri}"
45
- puts "Normalized params: #{request.normalized_parameters}" unless options[:xmpp]
46
- puts "Signature base string: #{request.signature_base_string}"
47
-
48
- if xmpp?
49
- puts
50
- puts "XMPP Stanza:"
51
- puts xmpp_output(request)
52
- puts
53
- puts "Note: You may want to use bare JIDs in your URI."
54
- puts
55
- else
56
- puts "OAuth Request URI: #{request.signed_uri}"
57
- puts "Request URI: #{request.signed_uri(false)}"
58
- puts "Authorization header: #{request.oauth_header(realm: options[:realm])}"
59
- end
60
- puts "Signature: #{request.oauth_signature}"
61
- puts "Escaped signature: #{OAuth::Helper.escape(request.oauth_signature)}"
62
- end
63
-
64
- def xmpp_output(request)
65
- <<-EOS
66
- <oauth xmlns='urn:xmpp:oauth:0'>
67
- <oauth_consumer_key>#{request.oauth_consumer_key}</oauth_consumer_key>
68
- <oauth_token>#{request.oauth_token}</oauth_token>
69
- <oauth_signature_method>#{request.oauth_signature_method}</oauth_signature_method>
70
- <oauth_signature>#{request.oauth_signature}</oauth_signature>
71
- <oauth_timestamp>#{request.oauth_timestamp}</oauth_timestamp>
72
- <oauth_nonce>#{request.oauth_nonce}</oauth_nonce>
73
- <oauth_version>#{request.oauth_version}</oauth_version>
74
- </oauth>
75
- EOS
76
- end
77
- end
78
- end
@@ -1,7 +0,0 @@
1
- class OAuth::CLI
2
- class VersionCommand < BaseCommand
3
- def run
4
- puts "OAuth Gem #{OAuth::VERSION}"
5
- end
6
- end
7
- end
data/lib/oauth/cli.rb DELETED
@@ -1,56 +0,0 @@
1
- require "optparse"
2
- require "oauth/cli/base_command"
3
- require "oauth/cli/help_command"
4
- require "oauth/cli/query_command"
5
- require "oauth/cli/authorize_command"
6
- require "oauth/cli/sign_command"
7
- require "oauth/cli/version_command"
8
- require "active_support/core_ext/string/inflections"
9
-
10
- module OAuth
11
- class CLI
12
- def self.puts_red(string)
13
- puts "\033[0;91m#{string}\033[0m"
14
- end
15
-
16
- ALIASES = {
17
- "h" => "help",
18
- "v" => "version",
19
- "q" => "query",
20
- "a" => "authorize",
21
- "s" => "sign"
22
- }.freeze
23
-
24
- def initialize(stdout, stdin, stderr, command, arguments)
25
- klass = get_command_class(parse_command(command))
26
- @command = klass.new(stdout, stdin, stderr, arguments)
27
- @help_command = HelpCommand.new(stdout, stdin, stderr, [])
28
- end
29
-
30
- def run
31
- @command.run
32
- end
33
-
34
- private
35
-
36
- def get_command_class(command)
37
- Object.const_get("OAuth::CLI::#{command.camelize}Command")
38
- end
39
-
40
- def parse_command(command)
41
- case command = command.to_s.downcase
42
- when "--version", "-v"
43
- "version"
44
- when "--help", "-h", nil, ""
45
- "help"
46
- when *ALIASES.keys
47
- ALIASES[command]
48
- when *ALIASES.values
49
- command
50
- else
51
- OAuth::CLI.puts_red "Command '#{command}' not found"
52
- "help"
53
- end
54
- end
55
- end
56
- end