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.



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

def keys
  @keys
end

.optionsObject

Returns the value of attribute options.



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

def options
  @options
end

Class Method Details

.authObject



75
76
77
# File 'lib/faraday/auth-hmac.rb', line 75

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

Instance Method Details

#authObject



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

def auth
  self.class.auth
end

#call(env) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/faraday/auth-hmac.rb', line 91

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

  @app.call(env)
end

#sign!(env, sign_with) ⇒ Object



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

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