Parent

Included Modules

Net::HTTPRequest

Attributes

oauth_helper[R]

Public Instance Methods

oauth!(http, consumer = nil, token = nil, options = {}) click to toggle source

Add the OAuth information to an HTTP request. Depending on the options[:scheme] setting this may add a header, additional query string parameters, or additional POST body parameters. The default scheme is header, in which the OAuth parameters as put into the Authorization header.

  • http - Configured Net::HTTP instance

  • consumer - OAuth::Consumer instance

  • token - OAuth::Token instance

  • options - Request-specific options (e.g. request_uri, consumer, token, scheme, signature_method, nonce, timestamp)

This method also modifies the User-Agent header to add the OAuth gem version.

See Also: OAuth core spec version 1.0, section 5.4.1,

          {OAuth Request Body Hash 1.0 Draft 4}[http://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/drafts/4/spec.html]
    # File lib/oauth/client/net_http.rb, line 25
25:   def oauth!(http, consumer = nil, token = nil, options = {})
26:     helper_options = oauth_helper_options(http, consumer, token, options)
27:     @oauth_helper = OAuth::Client::Helper.new(self, helper_options)
28:     @oauth_helper.amend_user_agent_header(self)
29:     @oauth_helper.hash_body if oauth_body_hash_required?
30:     self.send("set_oauth_#{helper_options[:scheme]}")
31:   end
signature_base_string(http, consumer = nil, token = nil, options = {}) click to toggle source

Create a string suitable for signing for an HTTP request. This process involves parameter normalization as specified in the OAuth specification. The exact normalization also depends on the options[:scheme] being used so this must match what will be used for the request itself. The default scheme is header, in which the OAuth parameters as put into the Authorization header.

  • http - Configured Net::HTTP instance

  • consumer - OAuth::Consumer instance

  • token - OAuth::Token instance

  • options - Request-specific options (e.g. request_uri, consumer, token, scheme, signature_method, nonce, timestamp)

See Also: OAuth core spec version 1.0, section 9.1.1,

          {OAuth Request Body Hash 1.0 Draft 4}[http://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/drafts/4/spec.html]
    # File lib/oauth/client/net_http.rb, line 47
47:   def signature_base_string(http, consumer = nil, token = nil, options = {})
48:     helper_options = oauth_helper_options(http, consumer, token, options)
49:     oauth_helper = OAuth::Client::Helper.new(self, helper_options)
50:     oauth_helper.hash_body if oauth_body_hash_required?
51:     oauth_helper.signature_base_string
52:   end

Private Instance Methods

oauth_body_hash_required?() click to toggle source
    # File lib/oauth/client/net_http.rb, line 93
93:   def oauth_body_hash_required?
94:     request_body_permitted? && content_type != "application/x-www-form-urlencoded"
95:   end
oauth_full_request_uri(http,options) click to toggle source
    # File lib/oauth/client/net_http.rb, line 66
66:   def oauth_full_request_uri(http,options)
67:     uri = URI.parse(self.path)
68:     uri.host = http.address
69:     uri.port = http.port
70: 
71:     if options[:request_endpoint] and options[:site]
72:         hostval = options[:site]
73:         if hostval.include?("http://")
74:            hostval["http://"] = ""
75:         end
76:         if hostval.include?("https://")
77:            hostval["https://"] = ""
78:         end
79:         uri.host = hostval
80:         uri.port = 80
81:     end
82: 
83:     if http.respond_to?(:use_ssl?) && http.use_ssl?
84:       uri.scheme = "https"
85:     else
86:       uri.scheme = "http"
87:     end
88: 
89: 
90:     uri.to_s
91:   end
oauth_helper_options(http, consumer, token, options) click to toggle source
    # File lib/oauth/client/net_http.rb, line 56
56:   def oauth_helper_options(http, consumer, token, options)
57:     { :request_uri      => oauth_full_request_uri(http,options),
58:       :consumer         => consumer,
59:       :token            => token,
60:       :scheme           => 'header',
61:       :signature_method => nil,
62:       :nonce            => nil,
63:       :timestamp        => nil }.merge(options)
64:   end
set_oauth_body() click to toggle source

FIXME: if you’re using a POST body and query string parameters, this method will move query string parameters into the body unexpectedly. This may cause problems with non-x-www-form-urlencoded bodies submitted to URLs containing query string params. If duplicate parameters are present in both places, all instances should be included when calculating the signature base string.

     # File lib/oauth/client/net_http.rb, line 108
108:   def set_oauth_body
109:     self.set_form_data(@oauth_helper.stringify_keys(@oauth_helper.parameters_with_oauth))
110:     params_with_sig = @oauth_helper.parameters.merge(:oauth_signature => @oauth_helper.signature)
111:     self.set_form_data(@oauth_helper.stringify_keys(params_with_sig))
112:   end
set_oauth_header() click to toggle source
    # File lib/oauth/client/net_http.rb, line 97
97:   def set_oauth_header
98:     self['Authorization'] = @oauth_helper.header
99:   end
set_oauth_query_string() click to toggle source
     # File lib/oauth/client/net_http.rb, line 114
114:   def set_oauth_query_string
115:     oauth_params_str = @oauth_helper.oauth_parameters.map { |k,v| [escape(k), escape(v)] * "=" }.join("&")
116:     uri = URI.parse(path)
117:     if uri.query.to_s == ""
118:       uri.query = oauth_params_str
119:     else
120:       uri.query = uri.query + "&" + oauth_params_str
121:     end
122: 
123:     @path = uri.to_s
124: 
125:     @path << "&oauth_signature=#{escape(oauth_helper.signature)}"
126:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.