Class: VectorMCP::Security::Strategies::Custom
- Inherits:
-
Object
- Object
- VectorMCP::Security::Strategies::Custom
- Defined in:
- lib/vector_mcp/security/strategies/custom.rb
Overview
Custom authentication strategy Allows developers to implement their own authentication logic
Instance Attribute Summary collapse
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
Instance Method Summary collapse
-
#authenticate(request) ⇒ Object, ...
Authenticate a request using the custom handler.
-
#configured? ⇒ Boolean
Check if handler is configured.
-
#initialize(&handler) ⇒ Custom
constructor
Initialize with a custom authentication handler.
Constructor Details
#initialize(&handler) ⇒ Custom
Initialize with a custom authentication handler
13 14 15 16 17 |
# File 'lib/vector_mcp/security/strategies/custom.rb', line 13 def initialize(&handler) raise ArgumentError, "Custom authentication strategy requires a block" unless handler @handler = handler end |
Instance Attribute Details
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
9 10 11 |
# File 'lib/vector_mcp/security/strategies/custom.rb', line 9 def handler @handler end |
Instance Method Details
#authenticate(request) ⇒ Object, ...
Authenticate a request using the custom handler.
The handler receives a RequestContext, which supports
hash-style access (request[:headers], request[:params]) for
compatibility with handlers written against the legacy request hash.
If the handler returns a Hash with a :user key, the value is extracted
so that AuthManager receives the user data directly.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vector_mcp/security/strategies/custom.rb', line 28 def authenticate(request) result = @handler.call(VectorMCP::RequestContext.coerce(request)) return false unless result && result != false return result unless result.is_a?(Hash) && result.key?(:user) result[:user] rescue StandardError, NoMemoryError false end |
#configured? ⇒ Boolean
Check if handler is configured
41 42 43 |
# File 'lib/vector_mcp/security/strategies/custom.rb', line 41 def configured? !@handler.nil? end |