Class: Rack::Authenticate::Middleware::Auth
- Inherits:
-
Rack::Auth::AbstractRequest
- Object
- Rack::Auth::AbstractRequest
- Rack::Authenticate::Middleware::Auth
- Defined in:
- lib/rack/authenticate/middleware.rb
Instance Method Summary collapse
- #access_id ⇒ Object
- #basic? ⇒ Boolean
- #calculated_digest ⇒ Object
- #canonicalized_request ⇒ Object
-
#content_md5 ⇒ Object
TODO: replace the request body with a proxy object that verifies this when it is read.
- #given_digest ⇒ Object
- #has_all_required_parts? ⇒ Boolean
- #has_content? ⇒ Boolean
- #hmac? ⇒ Boolean
-
#initialize(env, configuration = Configuration.new) ⇒ Auth
constructor
A new instance of Auth.
- #request ⇒ Object
- #secret_key ⇒ Object
- #valid? ⇒ Boolean
- #valid_current_date? ⇒ Boolean
Constructor Details
#initialize(env, configuration = Configuration.new) ⇒ Auth
Returns a new instance of Auth.
38 39 40 41 |
# File 'lib/rack/authenticate/middleware.rb', line 38 def initialize(env, configuration = Configuration.new) super(env) @configuration = configuration end |
Instance Method Details
#access_id ⇒ Object
90 91 92 |
# File 'lib/rack/authenticate/middleware.rb', line 90 def access_id @access_id ||= params.split(':').first end |
#basic? ⇒ Boolean
43 44 45 |
# File 'lib/rack/authenticate/middleware.rb', line 43 def basic? :basic == scheme end |
#calculated_digest ⇒ Object
102 103 104 |
# File 'lib/rack/authenticate/middleware.rb', line 102 def calculated_digest @calculated_digest ||= HMAC::SHA1.hexdigest(secret_key, canonicalized_request) end |
#canonicalized_request ⇒ Object
84 85 86 87 88 |
# File 'lib/rack/authenticate/middleware.rb', line 84 def canonicalized_request parts = [ request.request_method, request.url, date ] parts << content_md5 if has_content? parts.join("\n") end |
#content_md5 ⇒ Object
TODO: replace the request body with a proxy object that verifies this when it is read.
80 81 82 |
# File 'lib/rack/authenticate/middleware.rb', line 80 def content_md5 request.env['HTTP_CONTENT_MD5'] end |
#given_digest ⇒ Object
98 99 100 |
# File 'lib/rack/authenticate/middleware.rb', line 98 def given_digest @given_digest ||= params.split(':').last end |
#has_all_required_parts? ⇒ Boolean
51 52 53 54 55 56 57 58 59 |
# File 'lib/rack/authenticate/middleware.rb', line 51 def has_all_required_parts? return false unless date if has_content? content_md5.to_s != '' else true end end |
#has_content? ⇒ Boolean
75 76 77 |
# File 'lib/rack/authenticate/middleware.rb', line 75 def has_content? request.content_length.to_i > 0 end |
#hmac? ⇒ Boolean
47 48 49 |
# File 'lib/rack/authenticate/middleware.rb', line 47 def hmac? :hmac == scheme end |
#request ⇒ Object
61 62 63 |
# File 'lib/rack/authenticate/middleware.rb', line 61 def request @request ||= ::Rack::Request.new(@env) end |
#secret_key ⇒ Object
94 95 96 |
# File 'lib/rack/authenticate/middleware.rb', line 94 def secret_key @configuration.hmac_secret_key_for(access_id) end |
#valid? ⇒ Boolean
106 107 108 109 110 111 |
# File 'lib/rack/authenticate/middleware.rb', line 106 def valid? provided? && secret_key && valid_current_date? && calculated_digest == given_digest end |
#valid_current_date? ⇒ Boolean
65 66 67 68 69 70 71 72 73 |
# File 'lib/rack/authenticate/middleware.rb', line 65 def valid_current_date? = Time.httpdate(date) rescue ArgumentError return false else tolerance = @configuration. * 60 now = Time.now (now - tolerance) <= && (now + tolerance) >= end |