Class: Rack::UrlAuth

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

Defined Under Namespace

Classes: Proxy, Signer

Constant Summary collapse

VERSION =
"0.2.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, opts = {}) ⇒ UrlAuth

Returns a new instance of UrlAuth.



9
10
11
12
13
14
15
16
# File 'lib/rack/url_auth.rb', line 9

def initialize(app, opts = {})
  secret = opts[:secret] or
    raise(ArgumentError, 'Please provide `secret`')

  @app    = app
  @signer = Signer.new(secret)
  @forward_auth = !!opts[:forward_auth]
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



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

def app
  @app
end

#forward_authObject (readonly)

Returns the value of attribute forward_auth.



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

def forward_auth
  @forward_auth
end

#signerObject (readonly)

Returns the value of attribute signer.



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

def signer
  @signer
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/rack/url_auth.rb', line 18

def call(env)
  proxy = env['rack.signature_auth'] = Proxy.new(env, signer)

  if !@forward_auth && !proxy.authorized?
    [403, {}, ['Forbidden']]
  else
    @app.call(env)
  end
end