Class: Ey::Hmac::Adapter::Rack

Inherits:
Ey::Hmac::Adapter show all
Defined in:
lib/ey-hmac/adapter/rack.rb

Constant Summary

Constants inherited from Ey::Hmac::Adapter

AUTHORIZATION_REGEXP, DEFAULT_CANONICALIZE_WITH

Instance Attribute Summary

Attributes inherited from Ey::Hmac::Adapter

#accept_digests, #authorization_header, #canonicalize_with, #include_query_string, #options, #request, #service, #sign_with

Instance Method Summary collapse

Methods inherited from Ey::Hmac::Adapter

#authenticated!, #authenticated?, #authorization, #canonicalize, #signature

Constructor Details

#initialize(request, options) ⇒ Rack

Returns a new instance of Rack.



6
7
8
9
# File 'lib/ey-hmac/adapter/rack.rb', line 6

def initialize(request, options)
  super
  @request = request.is_a?(Hash) ? ::Rack::Request.new(request) : request
end

Instance Method Details

#authorization_signatureObject



57
58
59
# File 'lib/ey-hmac/adapter/rack.rb', line 57

def authorization_signature
  request.env["HTTP_#{authorization_header.to_s.upcase}"]
end

#bodyObject



27
28
29
30
31
32
33
34
# File 'lib/ey-hmac/adapter/rack.rb', line 27

def body
  if request.env['rack.input']
    request.env['rack.input'].rewind
    body = request.env['rack.input'].read
    request.env['rack.input'].rewind
    body == '' ? nil : body
  end
end

#content_digestObject



19
20
21
# File 'lib/ey-hmac/adapter/rack.rb', line 19

def content_digest
  request.env['HTTP_CONTENT_DIGEST']
end

#content_typeObject



15
16
17
# File 'lib/ey-hmac/adapter/rack.rb', line 15

def content_type
  request.content_type
end

#dateObject



36
37
38
# File 'lib/ey-hmac/adapter/rack.rb', line 36

def date
  request.env['HTTP_DATE']
end

#methodObject



11
12
13
# File 'lib/ey-hmac/adapter/rack.rb', line 11

def method
  request.request_method.to_s.upcase
end

#pathObject



44
45
46
# File 'lib/ey-hmac/adapter/rack.rb', line 44

def path
  request.path
end

#set_content_digestObject



23
24
25
# File 'lib/ey-hmac/adapter/rack.rb', line 23

def set_content_digest
  request.env['HTTP_CONTENT_DIGEST'] = Digest::MD5.hexdigest(body) if body
end

#set_dateObject



40
41
42
# File 'lib/ey-hmac/adapter/rack.rb', line 40

def set_date
  request.env['HTTP_DATE'] = Time.now.httpdate
end

#sign!(key_id, key_secret) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/ey-hmac/adapter/rack.rb', line 48

def sign!(key_id, key_secret)
  set_date
  set_content_digest

  request.env['HTTP_X_SIGNATURE_VERSION'] = options[:version] if options[:version]

  request.env["HTTP_#{authorization_header.to_s.upcase}"] = authorization(key_id, key_secret)
end