Class: Verikloak::Middleware
- Inherits:
-
Object
- Object
- Verikloak::Middleware
- Includes:
- MiddlewareErrorMapping
- Defined in:
- lib/verikloak/middleware.rb
Overview
Constant Summary
Constants included from MiddlewareErrorMapping
Verikloak::MiddlewareErrorMapping::AUTH_ERROR_CODES, Verikloak::MiddlewareErrorMapping::INFRA_ERROR_CODES
Instance Method Summary collapse
-
#call(env) ⇒ Array(Integer, Hash, Array<String>)
Rack entrypoint.
-
#initialize(app, discovery_url:, audience:, skip_paths: [], discovery: nil, jwks_cache: nil) ⇒ Middleware
constructor
A new instance of Middleware.
Methods included from MiddlewareErrorMapping
#auth_error?, #dependency_error_tuple, #fallback_tuple, #forbidden?, #infra_error_tuple
Constructor Details
#initialize(app, discovery_url:, audience:, skip_paths: [], discovery: nil, jwks_cache: nil) ⇒ Middleware
Returns a new instance of Middleware.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/verikloak/middleware.rb', line 94 def initialize(app, discovery_url:, audience:, skip_paths: [], discovery: nil, jwks_cache: nil) @app = app @audience = audience @skip_paths = skip_paths @discovery = discovery || Discovery.new(discovery_url: discovery_url) @jwks_cache = jwks_cache @issuer = nil @mutex = Mutex.new end |
Instance Method Details
#call(env) ⇒ Array(Integer, Hash, Array<String>)
Rack entrypoint.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/verikloak/middleware.rb', line 113 def call(env) path = env['PATH_INFO'] return @app.call(env) if skip?(path) token = extract_token(env) handle_request(env, token) rescue Verikloak::Error => e code, status = map_error(e) error_response(code, e., status) rescue StandardError => e log_internal_error(e) error_response('internal_server_error', 'An unexpected error occurred', 500) end |