Class: RailsVitals::MCP::Auth
- Inherits:
-
Object
- Object
- RailsVitals::MCP::Auth
- Defined in:
- lib/rails_vitals/mcp/auth.rb
Constant Summary collapse
- BEARER_PATTERN =
/\ABearer (.+)\z/
Instance Method Summary collapse
-
#initialize(token) ⇒ Auth
constructor
A new instance of Auth.
- #valid?(request) ⇒ Boolean
Constructor Details
#initialize(token) ⇒ Auth
Returns a new instance of Auth.
6 7 8 |
# File 'lib/rails_vitals/mcp/auth.rb', line 6 def initialize(token) @expected_token = token end |
Instance Method Details
#valid?(request) ⇒ Boolean
10 11 12 13 14 15 16 17 18 |
# File 'lib/rails_vitals/mcp/auth.rb', line 10 def valid?(request) return false if @expected_token.blank? auth_header = request.get_header("HTTP_AUTHORIZATION") || "" match = BEARER_PATTERN.match(auth_header) return false unless match ActiveSupport::SecurityUtils.secure_compare(match[1], @expected_token) end |