Class: Etna::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/etna/auth.rb

Direct Known Subclasses

TestAuth

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Auth

Returns a new instance of Auth.



6
7
8
# File 'lib/etna/auth.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/etna/auth.rb', line 10

def call(env)
  request = Rack::Request.new(env)

  # There are three ways to authenticate.
  # Either the route does not require auth,
  # you have an hmac or you have a valid token.
  # Both of these will not validate individual
  # permissions; this is up to the controller
  if [ approve_noauth(request), approve_hmac(request), approve_user(request) ].all?{|approved| !approved}
    return fail_or_redirect(request)
  end

  @app.call(request.env)
end