Sha256: d9e3546a2cf3879f07c6e81001981ce6a29a7df1bc88615055670d60705503f4

Contents?: true

Size: 950 Bytes

Versions: 5

Compression:

Stored size: 950 Bytes

Contents

require 'rack'

module SoarAuthenticationToken
  class RackMiddleware
    def initialize(app, configuration)
      @app = app
      @configuration = configuration
    end

    def call(env)
      request = Rack::Request.new env
      session, params = request.session, request.params
      valid, token_meta = validate_and_resolve_token(request.env['HTTP_AUTHORIZATION'],params['flow_identifier'])
      if valid
        session['user'] = token_meta['authenticated_identifier']
        session['auth_token_meta'] = token_meta
        @app.call env
      else
        [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
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
soar_authentication_token-2.0.3 lib/soar_authentication_token/rack_middleware.rb
soar_authentication_token-2.0.2 lib/soar_authentication_token/rack_middleware.rb
soar_authentication_token-2.0.1 lib/soar_authentication_token/rack_middleware.rb
soar_authentication_token-2.0.0 lib/soar_authentication_token/rack_middleware.rb
soar_authentication_token-1.0.0 lib/soar_authentication_token/rack_middleware.rb