Class: Hanko::Rails::Middleware
- Inherits:
-
Object
- Object
- Hanko::Rails::Middleware
- Defined in:
- lib/hanko/rails/middleware.rb
Overview
Rack middleware that extracts a Hanko JWT from the request cookie or
Authorization: Bearer header, verifies it against the Hanko JWKS
endpoint, and stores the decoded session payload in env['hanko.session'].
Paths listed in Configuration#exclude_paths are skipped entirely.
Instance Method Summary collapse
-
#call(env) ⇒ Array<(Integer, Hash, #each)>
Processes an incoming request, extracts and verifies the Hanko token, and forwards the request to the next middleware.
-
#initialize(app) ⇒ Middleware
constructor
Initializes the middleware with the next Rack application.
Constructor Details
#initialize(app) ⇒ Middleware
Initializes the middleware with the next Rack application.
15 16 17 |
# File 'lib/hanko/rails/middleware.rb', line 15 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Array<(Integer, Hash, #each)>
Processes an incoming request, extracts and verifies the Hanko token, and forwards the request to the next middleware.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hanko/rails/middleware.rb', line 24 def call(env) request = Rack::Request.new(env) unless excluded_path?(request.path) token = extract_token(request) env['hanko.session'] = verify_token(token) if token end @app.call(env) end |