Class: FaradayMiddleware::Authentication
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- FaradayMiddleware::Authentication
- Defined in:
- lib/faraday/authentication.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, key, secret) ⇒ Authentication
constructor
A new instance of Authentication.
Constructor Details
#initialize(app, key, secret) ⇒ Authentication
Returns a new instance of Authentication.
7 8 9 10 11 |
# File 'lib/faraday/authentication.rb', line 7 def initialize(app, key, secret) super(app) @key = key @secret = secret end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/faraday/authentication.rb', line 13 def call(env) return @app.call(env) if @key.nil? || @secret.nil? = (Time.now - 600).to_i.to_s method = env[:method].to_s.upcase path = env[:url].path + (env[:url].query ? '?' + env[:url].query : '') body = env[:body] || '' signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @secret, method + path + + body) env[:request_headers]['api-expires'] = env[:request_headers]['api-key'] = @key if @key env[:request_headers]['api-signature'] = signature @app.call env end |