Sha256: 324710f5bfd82832abe535f95dca609948f534564bccaa392a2c85cdaabbc111
Contents?: true
Size: 1.19 KB
Versions: 6
Compression:
Stored size: 1.19 KB
Contents
require 'rack' module SoarAuthenticationToken class RackMiddleware def initialize(app, configuration, auditing = nil) @app = app @configuration = configuration @auditing = auditing end def call(env) request = Rack::Request.new env session, params = request.session, request.params token_valid, token_meta, message = validate_and_resolve_token(request.env['HTTP_AUTHORIZATION'],params['flow_identifier']) if token_valid session['user'] = token_meta['authenticated_identifier'] session['auth_token_meta'] = token_meta @app.call env else audit_token_rejection("Token rejected due to #{message}",params['flow_identifier']) [401, {"Content-Type" => "text/html"}, ["401 - Not authenticated"]] end end private def validate_and_resolve_token(authentication_token,flow_identifier) token_validator = SoarAuthenticationToken::TokenValidator.new(@configuration) token_validator.validate(authentication_token: authentication_token,flow_identifier: flow_identifier) end def audit_token_rejection(message, flow_id) @auditing.warn(message,flow_id) if @auditing end end end
Version data entries
6 entries across 6 versions & 1 rubygems