Class: Rack::Middleware::AngusAuthentication

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/middleware/angus_authentication.rb

Constant Summary collapse

UNAUTHORIZED_MESSAGE =
'Unauthorized'
TIMEOUT_MESSAGE =
'Authentication Timeout'

Instance Method Summary collapse

Constructor Details

#initialize(app, settings = {}) ⇒ AngusAuthentication

Returns a new instance of AngusAuthentication.



11
12
13
14
15
# File 'lib/rack/middleware/angus_authentication.rb', line 11

def initialize(app, settings = {})
  @app = app

  @authentication_settings = settings
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
# File 'lib/rack/middleware/angus_authentication.rb', line 17

def call(env)
  dup.call!(env)
end

#call!(env) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rack/middleware/angus_authentication.rb', line 21

def call!(env)
  authentication_provider = Angus::Authentication::Provider.new(@authentication_settings, env)

  authentication_provider.authenticate!

  response = @app.call(env)

  authentication_provider.update_response_header(response)

  response
rescue Angus::Authentication::MissingAuthorizationData,
       Angus::Authentication::InvalidAuthorizationData
  [401, {}, [UNAUTHORIZED_MESSAGE]]
rescue Angus::Authentication::AuthorizationTimeout
  [419, {}, [TIMEOUT_MESSAGE]]
end