Class: RosettAi::Mcp::Middleware::Authentication
- Inherits:
-
Object
- Object
- RosettAi::Mcp::Middleware::Authentication
- Defined in:
- lib/rosett_ai/mcp/middleware/authentication.rb
Overview
Rack middleware for API key authentication.
Supports multi-key keyfile or single env var modes. Returns 401 Unauthorized for invalid credentials.
Instance Method Summary collapse
-
#call(env) ⇒ Array
Rack response triplet.
-
#initialize(app, config: nil) ⇒ Authentication
constructor
A new instance of Authentication.
Constructor Details
#initialize(app, config: nil) ⇒ Authentication
Returns a new instance of Authentication.
19 20 21 22 23 24 25 26 |
# File 'lib/rosett_ai/mcp/middleware/authentication.rb', line 19 def initialize(app, config: nil) @app = app @config = config @keyfile = nil validate_auth_type load_keyfile if keyfile_mode? install_sighup_handler if keyfile_mode? end |
Instance Method Details
#call(env) ⇒ Array
Returns Rack response triplet.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rosett_ai/mcp/middleware/authentication.rb', line 30 def call(env) case auth_type when 'none' env['rosett_ai.authenticated'] = false @app.call(env) when 'api_key' authenticate_api_key(env) else ('Unsupported authentication type') end end |