Faraday::Middleware
Public: Uses the simple_oauth library to sign requests according the OAuth protocol.
The options for this middleware are forwarded to SimpleOAuth::Header: :consumer_key, :consumer_secret, :token, :token_secret. All these parameters are optional.
The signature is added to the "Authorization" HTTP request header. If the value for this header already exists, it is not overriden.
For requests that have parameters in the body, such as POST, this middleware expects them to be in Hash form, i.e. not encoded to string. This means this middleware has to be positioned on the stack before any encoding middleware such as UrlEncoded.
# File lib/faraday_middleware/request/oauth.rb, line 52 def body_params(env) env[:body] || {} end
# File lib/faraday_middleware/request/oauth.rb, line 28 def call(env) env[:request_headers][AUTH_HEADER] ||= oauth_header(env).to_s if sign_request?(env) @app.call(env) end
# File lib/faraday_middleware/request/oauth.rb, line 33 def oauth_header(env) SimpleOAuth::Header.new env[:method], env[:url].to_s, signature_params(body_params(env)), oauth_options(env) end
# File lib/faraday_middleware/request/oauth.rb, line 44 def oauth_options(env) if extra = env[:request][:oauth] and extra.is_a? Hash and !extra.empty? @options.merge extra else @options end end
Generated with the Darkfish Rdoc Generator 2.