Class: Faraday::Request::AuthHMAC

Inherits:
Middleware
  • Object
show all
Defined in:
lib/faraday/auth-hmac.rb

Overview

Sign your request using AuthHMAC.

@connection.get('http://localhost/') do |req|
  req.sign! 'access_id', 'secret'
  req.body = 'abc'
end

This adds the Authorization, Content-MD5, and Date headers.

This middleware can be added and nothing will happen unless the ‘sign!` method is called (as in the example above).

Defined Under Namespace

Classes: CanonicalString

Constant Summary collapse

VERSION =
'1.0.1'
AUTH_HEADER =
"Authorization".freeze

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.keysObject

Returns the value of attribute keys.



64
65
66
# File 'lib/faraday/auth-hmac.rb', line 64

def keys
  @keys
end

.optionsObject

Returns the value of attribute options.



64
65
66
# File 'lib/faraday/auth-hmac.rb', line 64

def options
  @options
end

Class Method Details

.authObject



69
70
71
# File 'lib/faraday/auth-hmac.rb', line 69

def self.auth
  ::AuthHMAC.new(keys, options)
end

Instance Method Details

#authObject



72
73
74
# File 'lib/faraday/auth-hmac.rb', line 72

def auth
  self.class.auth
end

#call(env) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/faraday/auth-hmac.rb', line 84

def call(env)
  if sign_with = env.delete(:sign_with)
    sign!(env, sign_with)
  end

  @app.call(env)
end

#sign!(env, sign_with) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/faraday/auth-hmac.rb', line 76

def sign!(env, sign_with)
  self.auth.sign!(env, sign_with)

  # AuthHMAC doesn't set the Authorization header in the
  # `request_headers` hash.
  env[:request_headers][AUTH_HEADER] = env.delete(AUTH_HEADER)
end