Class: Rack::Authenticate::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/authenticate/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_id, secret_key, options = {}) ⇒ Client

Returns a new instance of Client.



9
10
11
12
# File 'lib/rack/authenticate/client.rb', line 9

def initialize(access_id, secret_key, options = {})
  @access_id, @secret_key = access_id, secret_key
  @ajax = options[:ajax]
end

Instance Attribute Details

#access_idObject (readonly)

Returns the value of attribute access_id.



8
9
10
# File 'lib/rack/authenticate/client.rb', line 8

def access_id
  @access_id
end

#secret_keyObject (readonly)

Returns the value of attribute secret_key.



8
9
10
# File 'lib/rack/authenticate/client.rb', line 8

def secret_key
  @secret_key
end

Instance Method Details

#request_signature_headers(method, url, content = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rack/authenticate/client.rb', line 14

def request_signature_headers(method, url, content = nil)
  {}.tap do |headers|
    headers[date_header_field] = date = Time.now.httpdate
    request = [method.to_s.upcase, url, date]

    if content
      content_md5 = Digest::MD5.hexdigest(content)
      headers['Content-MD5'] = content_md5
      request << content_md5
    end

    digest = HMAC::SHA1.hexdigest(secret_key, request.join("\n"))
    headers['Authorization'] = "HMAC #{access_id}:#{digest}"
  end
end