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. If the handler returns a Hash with a :user key, the value is extracted so that AuthManager receives the user data directly.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vector_mcp/security/strategies/custom.rb', line 25 def authenticate(request) result = @handler.call(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
38 39 40 |
# File 'lib/vector_mcp/security/strategies/custom.rb', line 38 def configured? !@handler.nil? end |