oauth 0.5.6 → 0.5.7.pre.pre1

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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +454 -0
  3. data/CODE_OF_CONDUCT.md +84 -0
  4. data/LICENSE +18 -17
  5. data/README.md +211 -0
  6. data/TODO +0 -0
  7. data/bin/oauth +2 -2
  8. data/lib/oauth/cli/authorize_command.rb +0 -0
  9. data/lib/oauth/cli/base_command.rb +1 -1
  10. data/lib/oauth/cli/help_command.rb +0 -0
  11. data/lib/oauth/cli/query_command.rb +0 -0
  12. data/lib/oauth/cli/sign_command.rb +0 -0
  13. data/lib/oauth/cli/version_command.rb +0 -0
  14. data/lib/oauth/cli.rb +18 -18
  15. data/lib/oauth/client/action_controller_request.rb +7 -7
  16. data/lib/oauth/client/em_http.rb +99 -99
  17. data/lib/oauth/client/helper.rb +22 -22
  18. data/lib/oauth/client/net_http.rb +5 -5
  19. data/lib/oauth/client.rb +0 -0
  20. data/lib/oauth/consumer.rb +49 -38
  21. data/lib/oauth/errors/error.rb +0 -0
  22. data/lib/oauth/errors/problem.rb +0 -0
  23. data/lib/oauth/errors/unauthorized.rb +3 -1
  24. data/lib/oauth/errors.rb +3 -3
  25. data/lib/oauth/helper.rb +11 -7
  26. data/lib/oauth/oauth.rb +0 -0
  27. data/lib/oauth/oauth_test_helper.rb +4 -4
  28. data/lib/oauth/request_proxy/action_controller_request.rb +9 -9
  29. data/lib/oauth/request_proxy/action_dispatch_request.rb +1 -1
  30. data/lib/oauth/request_proxy/base.rb +16 -16
  31. data/lib/oauth/request_proxy/curb_request.rb +5 -5
  32. data/lib/oauth/request_proxy/em_http_request.rb +18 -12
  33. data/lib/oauth/request_proxy/jabber_request.rb +3 -3
  34. data/lib/oauth/request_proxy/mock_request.rb +1 -1
  35. data/lib/oauth/request_proxy/net_http.rb +9 -9
  36. data/lib/oauth/request_proxy/rack_request.rb +4 -4
  37. data/lib/oauth/request_proxy/rest_client_request.rb +7 -7
  38. data/lib/oauth/request_proxy/typhoeus_request.rb +7 -7
  39. data/lib/oauth/request_proxy.rb +0 -0
  40. data/lib/oauth/server.rb +2 -2
  41. data/lib/oauth/signature/base.rb +8 -6
  42. data/lib/oauth/signature/hmac/sha1.rb +4 -4
  43. data/lib/oauth/signature/hmac/sha256.rb +4 -4
  44. data/lib/oauth/signature/plaintext.rb +2 -2
  45. data/lib/oauth/signature/rsa/sha1.rb +3 -3
  46. data/lib/oauth/signature.rb +0 -0
  47. data/lib/oauth/token.rb +5 -5
  48. data/lib/oauth/tokens/access_token.rb +3 -3
  49. data/lib/oauth/tokens/consumer_token.rb +0 -0
  50. data/lib/oauth/tokens/request_token.rb +0 -0
  51. data/lib/oauth/tokens/server_token.rb +0 -0
  52. data/lib/oauth/tokens/token.rb +0 -0
  53. data/lib/oauth/version.rb +1 -1
  54. data/lib/oauth.rb +8 -7
  55. metadata +171 -64
  56. data/README.rdoc +0 -88
data/README.md ADDED
@@ -0,0 +1,211 @@
1
+ # Ruby OAuth
2
+
3
+ ## Status
4
+
5
+ | Project | Ruby Oauth |
6
+ |--------------------------- |--------------------------- |
7
+ | name, license, docs | [![RubyGems.org](https://img.shields.io/badge/name-oauth-brightgreen.svg?style=flat)][rubygems] [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)][license-ref] [![RubyDoc.info](https://img.shields.io/badge/documentation-rubydoc-brightgreen.svg?style=flat)][documentation] |
8
+ | version & downloads | [![Version](https://img.shields.io/gem/v/oauth.svg)][rubygems] [![Downloads Today](https://img.shields.io/gem/rd/oauth.svg)][rubygems] [![Homepage](https://img.shields.io/badge/source-github-brightgreen.svg?style=flat)][source] |
9
+ | dependencies & linting | [![Depfu](https://badges.depfu.com/badges/d570491bac0ad3b0b65deb3c82028327/count.svg)][depfu] [![lint status](https://github.com/oauth-xx/oauth-ruby/actions/workflows/style.yml/badge.svg)][actions] |
10
+ | unit tests | [![supported rubies](https://github.com/oauth-xx/oauth-ruby/actions/workflows/supported.yml/badge.svg)][actions] [![unsupported status](https://github.com/oauth-xx/oauth-ruby/actions/workflows/unsupported.yml/badge.svg)][actions] |
11
+ | coverage & maintainability | [![Test Coverage](https://api.codeclimate.com/v1/badges/3cf23270c21e8791d788/test_coverage)][climate_coverage] [![codecov](https://codecov.io/gh/oauth-xx/oauth-ruby/branch/master/graph/badge.svg?token=4ZNAWNxrf9)][codecov_coverage] [![Maintainability](https://api.codeclimate.com/v1/badges/3cf23270c21e8791d788/maintainability)][climate_maintainability] |
12
+ | resources | [![Discussion](https://img.shields.io/badge/discussions-github-brightgreen.svg?style=flat)][gh_discussions] [![Mailing List](https://img.shields.io/badge/group-mailinglist-violet.svg?style=social&logo=google)][mailinglist] [![Join the chat at https://gitter.im/oauth-xx/oauth-ruby](https://badges.gitter.im/Join%20Chat.svg)][chat] [![Blog](https://img.shields.io/badge/blog-railsbling-brightgreen.svg?style=flat)][blogpage] |
13
+ | Spread ~♡ⓛⓞⓥⓔ♡~ | [![Open Source Helpers](https://www.codetriage.com/oauth-xx/oauth-ruby/badges/users.svg)][code_triage] [![Liberapay Patrons](https://img.shields.io/liberapay/patrons/pboling.svg?logo=liberapay)][liberapay_donate] [🌏][aboutme] [👼][angelme] [💻][coderme] [🌹][politicme] [![Tweet @ Peter][followme-img]][tweetme] |
14
+
15
+ ## What
16
+
17
+ This is a RubyGem for implementing both OAuth 1.0 clients and servers in Ruby
18
+ applications.
19
+
20
+ See the OAuth 1.0 spec http://oauth.net/core/1.0/
21
+
22
+ See the sibling gem [oauth2](https://github.com/oauth-xx/oauth2) for OAuth 2.0 implementations in Ruby.
23
+
24
+ ## Installation
25
+
26
+ Add this line to your application's Gemfile:
27
+
28
+ ```ruby
29
+ gem "oauth"
30
+ ```
31
+
32
+ And then execute:
33
+
34
+ $ bundle install
35
+
36
+ Or install it yourself as:
37
+
38
+ $ gem install oauth
39
+
40
+ ## Compatibility
41
+
42
+ Targeted ruby compatibility is non-EOL versions of Ruby, currently 2.6, 2.7, and
43
+ 3.0. Ruby is limited to 2.0+ in the gemspec, and this may change while the gem is
44
+ still at version 0.x.
45
+
46
+ ## Basics
47
+
48
+ This is a ruby library which is intended to be used in creating Ruby Consumer
49
+ and Service Provider applications. It is NOT a Rails plugin, but could easily
50
+ be used for the foundation for such a Rails plugin.
51
+
52
+ As a matter of fact it has been pulled out from an OAuth Rails GEM
53
+ (https://rubygems.org/gems/oauth-plugin https://github.com/pelle/oauth-plugin)
54
+ which now uses this gem as a dependency.
55
+
56
+ ## Usage
57
+
58
+ We need to specify the oauth_callback url explicitly, otherwise it defaults to
59
+ "oob" (Out of Band)
60
+
61
+ callback_url = "http://127.0.0.1:3000/oauth/callback"
62
+
63
+ Create a new `OAuth::Consumer` instance by passing it a configuration hash:
64
+
65
+ oauth_consumer = OAuth::Consumer.new("key", "secret", :site => "https://agree2")
66
+
67
+ Start the process by requesting a token
68
+
69
+ request_token = oauth_consumer.get_request_token(:oauth_callback => callback_url)
70
+
71
+ session[:token] = request_token.token
72
+ session[:token_secret] = request_token.secret
73
+ redirect_to request_token.authorize_url(:oauth_callback => callback_url)
74
+
75
+ When user returns create an access_token
76
+
77
+ hash = { oauth_token: session[:token], oauth_token_secret: session[:token_secret]}
78
+ request_token = OAuth::RequestToken.from_hash(oauth_consumer, hash)
79
+ access_token = request_token.get_access_token
80
+ # For 3-legged authorization, flow oauth_verifier is passed as param in callback
81
+ # access_token = request_token.get_access_token(oauth_verifier: params[:oauth_verifier])
82
+ @photos = access_token.get('/photos.xml')
83
+
84
+ Now that you have an access token, you can use Typhoeus to interact with the
85
+ OAuth provider if you choose.
86
+
87
+ require 'typhoeus'
88
+ require 'oauth/request_proxy/typhoeus_request'
89
+ oauth_params = {:consumer => oauth_consumer, :token => access_token}
90
+ hydra = Typhoeus::Hydra.new
91
+ req = Typhoeus::Request.new(uri, options) # :method needs to be specified in options
92
+ oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(:request_uri => uri))
93
+ req.options[:headers].merge!({"Authorization" => oauth_helper.header}) # Signs the request
94
+ hydra.queue(req)
95
+ hydra.run
96
+ @response = req.response
97
+
98
+ ## More Information
99
+
100
+ * RubyDoc Documentation: [![RubyDoc.info](https://img.shields.io/badge/documentation-rubydoc-brightgreen.svg?style=flat)][documentation]
101
+ * Mailing List/Google Group: [![Mailing List](https://img.shields.io/badge/group-mailinglist-violet.svg?style=social&logo=google)][mailinglist]
102
+ * GitHub Discussions: [![Discussion](https://img.shields.io/badge/discussions-github-brightgreen.svg?style=flat)][gh_discussions]
103
+ * Live Chat on Gitter: [![Join the chat at https://gitter.im/oauth-xx/oauth-ruby](https://badges.gitter.im/Join%20Chat.svg)][chat]
104
+ * Maintainer's Blog: [![Blog](https://img.shields.io/badge/blog-railsbling-brightgreen.svg?style=flat)][blogpage]
105
+
106
+ ## Contributing
107
+
108
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/oauth-xx/oauth-ruby][source]. This project is
109
+ intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to
110
+ the [code of conduct][conduct].
111
+
112
+ To submit a patch, please fork the oauth project and create a patch with
113
+ tests. Once you're happy with it send a pull request and post a message to the
114
+ [google group][mailinglist].
115
+
116
+ ## Contributors
117
+
118
+ [![Contributors](https://contrib.rocks/image?repo=oauth-xx/oauth-ruby)]("https://github.com/oauth-xx/oauth-ruby/graphs/contributors")
119
+
120
+ Made with [contributors-img](https://contrib.rocks).
121
+
122
+ ## Versioning
123
+
124
+ This library aims to adhere to [Semantic Versioning 2.0.0][semver]. Violations of this scheme should be reported as
125
+ bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, a new version should be
126
+ immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new
127
+ major versions.
128
+
129
+ As a result of this policy, you can (and should) specify a dependency on this gem using
130
+ the [Pessimistic Version Constraint][pvc] with two digits of precision.
131
+
132
+ For example:
133
+
134
+ ```ruby
135
+ spec.add_dependency "oauth", "~> 0.5"
136
+ ```
137
+
138
+ ## License
139
+
140
+ The gem is available as open source under the terms of
141
+ the [MIT License][license] [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)][license-ref].
142
+ See [LICENSE][license] for the [Copyright Notice][copyright-notice-explainer].
143
+
144
+ ## Contact
145
+
146
+ OAuth Ruby has been created and maintained by a large number of talented
147
+ individuals. The current maintainer is Peter Boling ([@pboling][gh_sponsors]).
148
+
149
+ Comments are welcome. Contact the [OAuth Ruby mailing list (Google Group)][mailinglist] or [GitHub Discussions][gh_discussions].
150
+
151
+ [copyright-notice-explainer]: https://opensource.stackexchange.com/questions/5778/why-do-licenses-such-as-the-mit-license-specify-a-single-year
152
+
153
+ [gh_discussions]: https://github.com/oauth-xx/oauth-ruby/discussions
154
+
155
+ [mailinglist]: http://groups.google.com/group/oauth-ruby
156
+
157
+ [conduct]: https://github.com/oauth-xx/oauth-ruby/blob/master/CODE_OF_CONDUCT.md
158
+
159
+ [license]: LICENSE
160
+
161
+ [license-ref]: https://opensource.org/licenses/MIT
162
+
163
+ [semver]: http://semver.org/
164
+
165
+ [pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint
166
+
167
+ [railsbling]: http://www.railsbling.com
168
+
169
+ [peterboling]: http://www.peterboling.com
170
+
171
+ [aboutme]: https://about.me/peter.boling
172
+
173
+ [angelme]: https://angel.co/peter-boling
174
+
175
+ [coderme]:http://coderwall.com/pboling
176
+
177
+ [followme-img]: https://img.shields.io/twitter/follow/galtzo.svg?style=social&label=Follow
178
+
179
+ [tweetme]: http://twitter.com/galtzo
180
+
181
+ [politicme]: https://nationalprogressiveparty.org
182
+
183
+ [documentation]: https://rubydoc.info/github/oauth-xx/oauth-ruby/main
184
+
185
+ [source]: https://github.com/oauth-xx/oauth-ruby/
186
+
187
+ [actions]: https://github.com/oauth-xx/oauth-ruby/actions
188
+
189
+ [issues]: https://github.com/oauth-xx/oauth-ruby/issues
190
+
191
+ [climate_maintainability]: https://codeclimate.com/github/oauth-xx/oauth-ruby/maintainability
192
+
193
+ [climate_coverage]: https://codeclimate.com/github/oauth-xx/oauth-ruby/test_coverage
194
+
195
+ [codecov_coverage]: https://codecov.io/gh/oauth-xx/oauth-ruby
196
+
197
+ [code_triage]: https://www.codetriage.com/oauth-xx/oauth-ruby
198
+
199
+ [depfu]: https://depfu.com/github/oauth-xx/oauth-ruby?project_id=22868
200
+
201
+ [blogpage]: http://www.railsbling.com/tags/oauth/
202
+
203
+ [rubygems]: https://rubygems.org/gems/oauth
204
+
205
+ [chat]: https://gitter.im/oauth-xx/oauth-ruby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
206
+
207
+ [maintenancee_policy]: https://guides.rubyonrails.org/maintenance_policy.html#security-issues
208
+
209
+ [liberapay_donate]: https://liberapay.com/pboling/donate
210
+
211
+ [gh_sponsors]: https://github.com/sponsors/pboling
data/TODO CHANGED
File without changes
data/bin/oauth CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require_relative "../lib/oauth"
4
- require 'oauth/cli'
4
+ require "oauth/cli"
5
5
 
6
6
  Signal.trap("INT") { puts; exit(1) } # don't dump a backtrace on a ^C
7
7
 
8
- ARGV << 'help' if ARGV.empty?
8
+ ARGV << "help" if ARGV.empty?
9
9
  command = ARGV.shift
10
10
 
11
11
  OAuth::CLI.new(STDOUT, STDIN, STDERR, command, ARGV).run
File without changes
@@ -26,7 +26,7 @@ class OAuth::CLI
26
26
  attr_reader :options
27
27
 
28
28
  def show_missing(array)
29
- array = array.map { |s| "--#{s}" }.join(' ')
29
+ array = array.map { |s| "--#{s}" }.join(" ")
30
30
  OAuth::CLI.puts_red "Options missing to OAuth CLI: #{array}"
31
31
  end
32
32
 
File without changes
File without changes
File without changes
File without changes
data/lib/oauth/cli.rb CHANGED
@@ -1,11 +1,11 @@
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'
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
9
 
10
10
  module OAuth
11
11
  class CLI
@@ -14,11 +14,11 @@ module OAuth
14
14
  end
15
15
 
16
16
  ALIASES = {
17
- 'h' => 'help',
18
- 'v' => 'version',
19
- 'q' => 'query',
20
- 'a' => 'authorize',
21
- 's' => 'sign',
17
+ "h" => "help",
18
+ "v" => "version",
19
+ "q" => "query",
20
+ "a" => "authorize",
21
+ "s" => "sign",
22
22
  }
23
23
 
24
24
  def initialize(stdout, stdin, stderr, command, arguments)
@@ -39,17 +39,17 @@ module OAuth
39
39
 
40
40
  def parse_command(command)
41
41
  case command = command.to_s.downcase
42
- when '--version', '-v'
43
- 'version'
44
- when '--help', '-h', nil, ''
45
- 'help'
42
+ when "--version", "-v"
43
+ "version"
44
+ when "--help", "-h", nil, ""
45
+ "help"
46
46
  when *ALIASES.keys
47
47
  ALIASES[command]
48
48
  when *ALIASES.values
49
49
  command
50
50
  else
51
51
  OAuth::CLI.puts_red "Command '#{command}' not found"
52
- 'help'
52
+ "help"
53
53
  end
54
54
  end
55
55
  end
@@ -1,10 +1,10 @@
1
1
  if defined? ActionDispatch
2
- require 'oauth/request_proxy/rack_request'
3
- require 'oauth/request_proxy/action_dispatch_request'
4
- require 'action_dispatch/testing/test_process'
2
+ require "oauth/request_proxy/rack_request"
3
+ require "oauth/request_proxy/action_dispatch_request"
4
+ require "action_dispatch/testing/test_process"
5
5
  else
6
- require 'oauth/request_proxy/action_controller_request'
7
- require 'action_controller/test_process'
6
+ require "oauth/request_proxy/action_controller_request"
7
+ require "action_controller/test_process"
8
8
  end
9
9
 
10
10
  module ActionController
@@ -35,7 +35,7 @@ module ActionController
35
35
  def configure_oauth(consumer = nil, token = nil, options = {})
36
36
  @oauth_options = { :consumer => consumer,
37
37
  :token => token,
38
- :scheme => 'header',
38
+ :scheme => "header",
39
39
  :signature_method => nil,
40
40
  :nonce => nil,
41
41
  :timestamp => nil }.merge(options)
@@ -51,7 +51,7 @@ module ActionController
51
51
  end
52
52
 
53
53
  def set_oauth_header
54
- env['Authorization'] = @oauth_helper.header
54
+ env["Authorization"] = @oauth_helper.header
55
55
  end
56
56
 
57
57
  def set_oauth_parameters
@@ -1,119 +1,119 @@
1
- require 'em-http'
2
- require 'oauth/helper'
3
- require 'oauth/request_proxy/em_http_request'
1
+ require "em-http"
2
+ require "oauth/helper"
3
+ require "oauth/request_proxy/em_http_request"
4
4
 
5
5
  # Extensions for em-http so that we can use consumer.sign! with an EventMachine::HttpClient
6
6
  # instance. This is purely syntactic sugar.
7
- class EventMachine::HttpClient
7
+ module EventMachine
8
+ class HttpClient
9
+ attr_reader :oauth_helper
8
10
 
9
- attr_reader :oauth_helper
11
+ # Add the OAuth information to an HTTP request. Depending on the <tt>options[:scheme]</tt> setting
12
+ # this may add a header, additional query string parameters, or additional POST body parameters.
13
+ # The default scheme is +header+, in which the OAuth parameters as put into the +Authorization+
14
+ # header.
15
+ #
16
+ # * http - Configured Net::HTTP instance, ignored in this scenario except for getting host.
17
+ # * consumer - OAuth::Consumer instance
18
+ # * token - OAuth::Token instance
19
+ # * options - Request-specific options (e.g. +request_uri+, +consumer+, +token+, +scheme+,
20
+ # +signature_method+, +nonce+, +timestamp+)
21
+ #
22
+ # This method also modifies the <tt>User-Agent</tt> header to add the OAuth gem version.
23
+ #
24
+ # See Also: {OAuth core spec version 1.0, section 5.4.1}[http://oauth.net/core/1.0#rfc.section.5.4.1]
25
+ def oauth!(http, consumer = nil, token = nil, options = {})
26
+ options = { :request_uri => normalized_oauth_uri(http),
27
+ :consumer => consumer,
28
+ :token => token,
29
+ :scheme => "header",
30
+ :signature_method => nil,
31
+ :nonce => nil,
32
+ :timestamp => nil }.merge(options)
10
33
 
11
- # Add the OAuth information to an HTTP request. Depending on the <tt>options[:scheme]</tt> setting
12
- # this may add a header, additional query string parameters, or additional POST body parameters.
13
- # The default scheme is +header+, in which the OAuth parameters as put into the +Authorization+
14
- # header.
15
- #
16
- # * http - Configured Net::HTTP instance, ignored in this scenario except for getting host.
17
- # * consumer - OAuth::Consumer instance
18
- # * token - OAuth::Token instance
19
- # * options - Request-specific options (e.g. +request_uri+, +consumer+, +token+, +scheme+,
20
- # +signature_method+, +nonce+, +timestamp+)
21
- #
22
- # This method also modifies the <tt>User-Agent</tt> header to add the OAuth gem version.
23
- #
24
- # See Also: {OAuth core spec version 1.0, section 5.4.1}[http://oauth.net/core/1.0#rfc.section.5.4.1]
25
- def oauth!(http, consumer = nil, token = nil, options = {})
26
- options = { :request_uri => normalized_oauth_uri(http),
27
- :consumer => consumer,
28
- :token => token,
29
- :scheme => 'header',
30
- :signature_method => nil,
31
- :nonce => nil,
32
- :timestamp => nil }.merge(options)
33
-
34
- @oauth_helper = OAuth::Client::Helper.new(self, options)
35
- self.__send__(:"set_oauth_#{options[:scheme]}")
36
- end
34
+ @oauth_helper = OAuth::Client::Helper.new(self, options)
35
+ self.__send__(:"set_oauth_#{options[:scheme]}")
36
+ end
37
37
 
38
- # Create a string suitable for signing for an HTTP request. This process involves parameter
39
- # normalization as specified in the OAuth specification. The exact normalization also depends
40
- # on the <tt>options[:scheme]</tt> being used so this must match what will be used for the request
41
- # itself. The default scheme is +header+, in which the OAuth parameters as put into the +Authorization+
42
- # header.
43
- #
44
- # * http - Configured Net::HTTP instance
45
- # * consumer - OAuth::Consumer instance
46
- # * token - OAuth::Token instance
47
- # * options - Request-specific options (e.g. +request_uri+, +consumer+, +token+, +scheme+,
48
- # +signature_method+, +nonce+, +timestamp+)
49
- #
50
- # See Also: {OAuth core spec version 1.0, section 9.1.1}[http://oauth.net/core/1.0#rfc.section.9.1.1]
51
- def signature_base_string(http, consumer = nil, token = nil, options = {})
52
- options = { :request_uri => normalized_oauth_uri(http),
53
- :consumer => consumer,
54
- :token => token,
55
- :scheme => 'header',
56
- :signature_method => nil,
57
- :nonce => nil,
58
- :timestamp => nil }.merge(options)
38
+ # Create a string suitable for signing for an HTTP request. This process involves parameter
39
+ # normalization as specified in the OAuth specification. The exact normalization also depends
40
+ # on the <tt>options[:scheme]</tt> being used so this must match what will be used for the request
41
+ # itself. The default scheme is +header+, in which the OAuth parameters as put into the +Authorization+
42
+ # header.
43
+ #
44
+ # * http - Configured Net::HTTP instance
45
+ # * consumer - OAuth::Consumer instance
46
+ # * token - OAuth::Token instance
47
+ # * options - Request-specific options (e.g. +request_uri+, +consumer+, +token+, +scheme+,
48
+ # +signature_method+, +nonce+, +timestamp+)
49
+ #
50
+ # See Also: {OAuth core spec version 1.0, section 9.1.1}[http://oauth.net/core/1.0#rfc.section.9.1.1]
51
+ def signature_base_string(http, consumer = nil, token = nil, options = {})
52
+ options = { :request_uri => normalized_oauth_uri(http),
53
+ :consumer => consumer,
54
+ :token => token,
55
+ :scheme => "header",
56
+ :signature_method => nil,
57
+ :nonce => nil,
58
+ :timestamp => nil }.merge(options)
59
59
 
60
- OAuth::Client::Helper.new(self, options).signature_base_string
61
- end
60
+ OAuth::Client::Helper.new(self, options).signature_base_string
61
+ end
62
62
 
63
- # This code was lifted from the em-http-request because it was removed from
64
- # the gem June 19, 2010
65
- # see: http://github.com/igrigorik/em-http-request/commit/d536fc17d56dbe55c487eab01e2ff9382a62598b
66
- def normalize_uri
67
- @normalized_uri ||= begin
68
- uri = @uri.dup
69
- encoded_query = encode_query(@uri, @options[:query])
70
- path, query = encoded_query.split("?", 2)
71
- uri.query = query unless encoded_query.empty?
72
- uri.path = path
73
- uri
63
+ # This code was lifted from the em-http-request because it was removed from
64
+ # the gem June 19, 2010
65
+ # see: http://github.com/igrigorik/em-http-request/commit/d536fc17d56dbe55c487eab01e2ff9382a62598b
66
+ def normalize_uri
67
+ @normalized_uri ||= begin
68
+ uri = @conn.dup
69
+ encoded_query = encode_query(@conn, @req[:query])
70
+ path, query = encoded_query.split("?", 2)
71
+ uri.query = query unless encoded_query.empty?
72
+ uri.path = path
73
+ uri
74
+ end
74
75
  end
75
- end
76
76
 
77
- protected
77
+ protected
78
78
 
79
- def combine_query(path, query, uri_query)
80
- combined_query = if query.kind_of?(Hash)
81
- query.map { |k, v| encode_param(k, v) }.join('&')
82
- else
83
- query.to_s
79
+ def combine_query(path, query, uri_query)
80
+ combined_query = if query.kind_of?(Hash)
81
+ query.map { |k, v| encode_param(k, v) }.join("&")
82
+ else
83
+ query.to_s
84
+ end
85
+ if !uri_query.to_s.empty?
86
+ combined_query = [combined_query, uri_query].reject {|part| part.empty?}.join("&")
87
+ end
88
+ combined_query.to_s.empty? ? path : "#{path}?#{combined_query}"
84
89
  end
85
- if !uri_query.to_s.empty?
86
- combined_query = [combined_query, uri_query].reject {|part| part.empty?}.join("&")
87
- end
88
- combined_query.to_s.empty? ? path : "#{path}?#{combined_query}"
89
- end
90
90
 
91
- # Since we expect to get the host etc details from the http instance (...),
92
- # we create a fake url here. Surely this is a horrible, horrible idea?
93
- def normalized_oauth_uri(http)
94
- uri = URI.parse(normalize_uri.path)
95
- uri.host = http.address
96
- uri.port = http.port
91
+ # Since we expect to get the host etc details from the http instance (...),
92
+ # we create a fake url here. Surely this is a horrible, horrible idea?
93
+ def normalized_oauth_uri(http)
94
+ uri = URI.parse(normalize_uri.path)
95
+ uri.host = http.address
96
+ uri.port = http.port
97
97
 
98
- if http.respond_to?(:use_ssl?) && http.use_ssl?
99
- uri.scheme = "https"
100
- else
101
- uri.scheme = "http"
98
+ if http.respond_to?(:use_ssl?) && http.use_ssl?
99
+ uri.scheme = "https"
100
+ else
101
+ uri.scheme = "http"
102
+ end
103
+ uri.to_s
102
104
  end
103
- uri.to_s
104
- end
105
105
 
106
- def set_oauth_header
107
- headers = (self.options[:head] ||= {})
108
- headers['Authorization'] = @oauth_helper.header
109
- end
106
+ def set_oauth_header
107
+ self.req[:head] ||= {}
108
+ self.req[:head].merge!("Authorization" => @oauth_helper.header)
109
+ end
110
110
 
111
- def set_oauth_body
112
- raise NotImplementedError, 'please use the set_oauth_header method instead'
113
- end
111
+ def set_oauth_body
112
+ raise NotImplementedError, "please use the set_oauth_header method instead"
113
+ end
114
114
 
115
- def set_oauth_query_string
116
- raise NotImplementedError, 'please use the set_oauth_header method instead'
115
+ def set_oauth_query_string
116
+ raise NotImplementedError, "please use the set_oauth_header method instead"
117
+ end
117
118
  end
118
-
119
119
  end
@@ -1,8 +1,8 @@
1
- require 'oauth/client'
2
- require 'oauth/consumer'
3
- require 'oauth/helper'
4
- require 'oauth/token'
5
- require 'oauth/signature/hmac/sha1'
1
+ require "oauth/client"
2
+ require "oauth/consumer"
3
+ require "oauth/helper"
4
+ require "oauth/token"
5
+ require "oauth/signature/hmac/sha1"
6
6
 
7
7
  module OAuth::Client
8
8
  class Helper
@@ -11,7 +11,7 @@ module OAuth::Client
11
11
  def initialize(request, options = {})
12
12
  @request = request
13
13
  @options = options
14
- @options[:signature_method] ||= 'HMAC-SHA1'
14
+ @options[:signature_method] ||= "HMAC-SHA1"
15
15
  end
16
16
 
17
17
  def options
@@ -28,22 +28,22 @@ module OAuth::Client
28
28
 
29
29
  def oauth_parameters
30
30
  out = {
31
- 'oauth_body_hash' => options[:body_hash],
32
- 'oauth_callback' => options[:oauth_callback],
33
- 'oauth_consumer_key' => options[:consumer].key,
34
- 'oauth_token' => options[:token] ? options[:token].token : '',
35
- 'oauth_signature_method' => options[:signature_method],
36
- 'oauth_timestamp' => timestamp,
37
- 'oauth_nonce' => nonce,
38
- 'oauth_verifier' => options[:oauth_verifier],
39
- 'oauth_version' => (options[:oauth_version] || '1.0'),
40
- 'oauth_session_handle' => options[:oauth_session_handle]
31
+ "oauth_body_hash" => options[:body_hash],
32
+ "oauth_callback" => options[:oauth_callback],
33
+ "oauth_consumer_key" => options[:consumer].key,
34
+ "oauth_token" => options[:token] ? options[:token].token : "",
35
+ "oauth_signature_method" => options[:signature_method],
36
+ "oauth_timestamp" => timestamp,
37
+ "oauth_nonce" => nonce,
38
+ "oauth_verifier" => options[:oauth_verifier],
39
+ "oauth_version" => (options[:oauth_version] || "1.0"),
40
+ "oauth_session_handle" => options[:oauth_session_handle]
41
41
  }
42
42
  allowed_empty_params = options[:allow_empty_params]
43
43
  if allowed_empty_params != true && !allowed_empty_params.kind_of?(Array)
44
44
  allowed_empty_params = allowed_empty_params == false ? [] : [allowed_empty_params]
45
45
  end
46
- out.select! { |k,v| v.to_s != '' || allowed_empty_params == true || allowed_empty_params.include?(k) }
46
+ out.select! { |k,v| v.to_s != "" || allowed_empty_params == true || allowed_empty_params.include?(k) }
47
47
  out
48
48
  end
49
49
 
@@ -73,18 +73,18 @@ module OAuth::Client
73
73
  def amend_user_agent_header(headers)
74
74
  @oauth_ua_string ||= "OAuth gem v#{OAuth::VERSION}"
75
75
  # Net::HTTP in 1.9 appends Ruby
76
- if headers['User-Agent'] && headers['User-Agent'] != 'Ruby'
77
- headers['User-Agent'] += " (#{@oauth_ua_string})"
76
+ if headers["User-Agent"] && headers["User-Agent"] != "Ruby"
77
+ headers["User-Agent"] += " (#{@oauth_ua_string})"
78
78
  else
79
- headers['User-Agent'] = @oauth_ua_string
79
+ headers["User-Agent"] = @oauth_ua_string
80
80
  end
81
81
  end
82
82
 
83
83
  def header
84
84
  parameters = oauth_parameters
85
- parameters.merge!('oauth_signature' => signature(options.merge(:parameters => parameters)))
85
+ parameters.merge!("oauth_signature" => signature(options.merge(:parameters => parameters)))
86
86
 
87
- header_params_str = parameters.sort.map { |k,v| "#{k}=\"#{escape(v)}\"" }.join(', ')
87
+ header_params_str = parameters.sort.map { |k,v| "#{k}=\"#{escape(v)}\"" }.join(", ")
88
88
 
89
89
  realm = "realm=\"#{options[:realm]}\", " if options[:realm]
90
90
  "OAuth #{realm}#{header_params_str}"