Class: Prescient::MCP::Authentication::BearerToken
- Inherits:
-
Object
- Object
- Prescient::MCP::Authentication::BearerToken
- Defined in:
- lib/prescient/mcp/authentication.rb
Overview
Authenticates requests with a configured bearer token.
Instance Method Summary collapse
-
#call(env) ⇒ Object, false
Authenticate a Rack environment without exposing the token.
-
#initialize(token:, principal: nil) ⇒ BearerToken
constructor
A new instance of BearerToken.
Constructor Details
#initialize(token:, principal: nil) ⇒ BearerToken
Returns a new instance of BearerToken.
11 12 13 14 15 16 |
# File 'lib/prescient/mcp/authentication.rb', line 11 def initialize(token:, principal: nil) raise ArgumentError, "token must be a non-empty string" unless token.is_a?(String) && !token.empty? @token = token @principal = principal end |
Instance Method Details
#call(env) ⇒ Object, false
Authenticate a Rack environment without exposing the token.
21 22 23 24 25 26 27 |
# File 'lib/prescient/mcp/authentication.rb', line 21 def call(env) value = env["HTTP_AUTHORIZATION"].to_s scheme, candidate = value.split(" ", 2) return false unless scheme&.casecmp("Bearer")&.zero? && secure_equal?(candidate.to_s, @token) @principal || { type: "bearer" } end |