Class: RailsAiBridge::Mcp::Auth::Strategies::BearerToken
- Inherits:
-
BaseStrategy
- Object
- BaseStrategy
- RailsAiBridge::Mcp::Auth::Strategies::BearerToken
- Defined in:
- lib/rails_ai_bridge/mcp/auth/strategies/bearer_token.rb
Overview
Authenticates HTTP MCP requests using a Bearer token.
Supports two modes, selected at construction time:
Resolver mode — when +token_resolver+ is provided the raw Bearer string is passed to the lambda; a truthy return value becomes the RailsAiBridge::Mcp::AuthResult#context. Use this to look up a user from a database token or validate an opaque API key via a third-party service.
Static secret mode — when no resolver is given the token is compared timing-safely to the value returned by +static_token_provider+. Suitable for shared secrets in +config.http_mcp_token+ / ENV.
Instance Method Summary collapse
-
#authenticate(request) ⇒ AuthResult
Authenticates the incoming request.
-
#initialize(static_token_provider:, token_resolver: nil) ⇒ BearerToken
constructor
A new instance of BearerToken.
Methods inherited from BaseStrategy
Constructor Details
#initialize(static_token_provider:, token_resolver: nil) ⇒ BearerToken
Returns a new instance of BearerToken.
33 34 35 36 37 |
# File 'lib/rails_ai_bridge/mcp/auth/strategies/bearer_token.rb', line 33 def initialize(static_token_provider:, token_resolver: nil) super() @static_token_provider = static_token_provider @token_resolver = token_resolver end |
Instance Method Details
#authenticate(request) ⇒ AuthResult
Authenticates the incoming request.
43 44 45 46 47 |
# File 'lib/rails_ai_bridge/mcp/auth/strategies/bearer_token.rb', line 43 def authenticate(request) return authenticate_via_resolver(request) if @token_resolver authenticate_via_static_secret(request) end |