Class: Rack::U2f::AuthenticationMiddleware

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/rack/u2f/authentication_middleware.rb

Overview

Middleware to authenticate against registered u2f keys

Instance Method Summary collapse

Methods included from Helpers

#extract_app_id

Constructor Details

#initialize(app, config = nil) ⇒ AuthenticationMiddleware

Returns a new instance of AuthenticationMiddleware.



7
8
9
10
11
# File 'lib/rack/u2f/authentication_middleware.rb', line 7

def initialize(app, config = nil)
  @app = app
  @store = config[:store] || raise('Please specify a U2F store such as Rack::U2f::RegistrationStore::RedisStore.new')
  @exclude_urls = config[:exclude_urls] || [/\A\/u2f/]
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/rack/u2f/authentication_middleware.rb', line 13

def call(env)
  request = Rack::Request.new(env)
  return @app.call(env) if excluded?(request)
  return @app.call(env) if authenticated?(request)
  return resp_auth_from_u2f(request) if request.params['u2f_auth']
  challenge_page(request)
end