Class: Verikloak::Rails::RequestStoreMirror
- Inherits:
-
Object
- Object
- Verikloak::Rails::RequestStoreMirror
- Defined in:
- lib/verikloak/rails/request_store_mirror.rb
Overview
Rack middleware that mirrors the Verikloak request context from the
Rack env into RequestStore, so code running outside the controller
(service objects, jobs enqueued during the request) can read the same
values through the controller helpers' RequestStore fallback.
The Railtie inserts this middleware right after Verikloak::Middleware
and only when the request_store gem is loaded. Values are written on
every request (including nil on skipped/unauthenticated paths) so no
stale context leaks between requests even before request_store's own
cleanup middleware runs. Applications that mirrored these keys by hand
before this middleware existed should remove their own writer — it
would otherwise be overwritten here.
Mirroring is best-effort: a failure never breaks the request, but it is logged (once per middleware instance) so a silently dead fallback does not go unnoticed.
Instance Method Summary collapse
-
#call(env) ⇒ Array
Mirror claims/token into RequestStore, then call downstream.
-
#initialize(app) ⇒ RequestStoreMirror
constructor
A new instance of RequestStoreMirror.
Constructor Details
#initialize(app) ⇒ RequestStoreMirror
Returns a new instance of RequestStoreMirror.
25 26 27 28 |
# File 'lib/verikloak/rails/request_store_mirror.rb', line 25 def initialize(app) @app = app @failure_warned = false end |
Instance Method Details
#call(env) ⇒ Array
Mirror claims/token into RequestStore, then call downstream.
34 35 36 37 |
# File 'lib/verikloak/rails/request_store_mirror.rb', line 34 def call(env) mirror(env) @app.call(env) end |