Class: Rack::UrlAuth::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/url_auth/proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, signer) ⇒ Proxy

Returns a new instance of Proxy.



6
7
8
9
# File 'lib/rack/url_auth/proxy.rb', line 6

def initialize(env, signer)
  @request = Rack::Request.new(env)
  @signer  = signer
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



4
5
6
# File 'lib/rack/url_auth/proxy.rb', line 4

def request
  @request
end

#signerObject (readonly)

Returns the value of attribute signer.



4
5
6
# File 'lib/rack/url_auth/proxy.rb', line 4

def signer
  @signer
end

Instance Method Details

#authorized?Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rack/url_auth/proxy.rb', line 11

def authorized?
  method = request.request_method.downcase
  signature_header = request.env["HTTP_X_SIGNATURE"]

  if !signature_header && request.get? || request.head?
    signer.verify_url(request.url, method)
  else
    body = request.body.read; request.body.rewind
    signer.verify(method + request.url + body, signature_header)
  end
end