Class: VectorMCP::Security::AuthManager
- Inherits:
-
Object
- Object
- VectorMCP::Security::AuthManager
- Defined in:
- lib/vector_mcp/security/auth_manager.rb
Overview
Manages authentication strategies for VectorMCP servers Provides opt-in authentication with zero configuration by default
Instance Attribute Summary collapse
-
#default_strategy ⇒ Object
readonly
Returns the value of attribute default_strategy.
-
#enabled ⇒ Object
readonly
Returns the value of attribute enabled.
-
#strategies ⇒ Object
readonly
Returns the value of attribute strategies.
Instance Method Summary collapse
-
#add_strategy(name, strategy) ⇒ Object
Add an authentication strategy.
-
#authenticate(request, strategy: nil) ⇒ AuthResult
Authenticate a request using the specified or default strategy.
-
#available_strategies ⇒ Array<Symbol>
Get list of available strategies.
-
#disable! ⇒ Object
Disable authentication (return to pass-through mode).
-
#enable!(default_strategy: :api_key) ⇒ Object
Enable authentication with optional default strategy.
-
#initialize ⇒ AuthManager
constructor
A new instance of AuthManager.
-
#remove_strategy(name) ⇒ Object
Remove an authentication strategy.
-
#required? ⇒ Boolean
Check if authentication is required.
Constructor Details
#initialize ⇒ AuthManager
Returns a new instance of AuthManager.
12 13 14 15 16 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 12 def initialize @strategies = {} @enabled = false @default_strategy = nil end |
Instance Attribute Details
#default_strategy ⇒ Object (readonly)
Returns the value of attribute default_strategy.
10 11 12 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 10 def default_strategy @default_strategy end |
#enabled ⇒ Object (readonly)
Returns the value of attribute enabled.
10 11 12 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 10 def enabled @enabled end |
#strategies ⇒ Object (readonly)
Returns the value of attribute strategies.
10 11 12 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 10 def strategies @strategies end |
Instance Method Details
#add_strategy(name, strategy) ⇒ Object
Add an authentication strategy
34 35 36 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 34 def add_strategy(name, strategy) @strategies[name] = strategy end |
#authenticate(request, strategy: nil) ⇒ AuthResult
Authenticate a request using the specified or default strategy
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 48 def authenticate(request, strategy: nil) return AuthResult.passthrough unless @enabled strategy_name = strategy || @default_strategy auth_strategy = @strategies[strategy_name] return AuthResult.failure unless auth_strategy result = auth_strategy.authenticate(request) if result == false AuthResult.failure else AuthResult.success(user: result, strategy: strategy_name.to_s) end rescue StandardError AuthResult.failure end |
#available_strategies ⇒ Array<Symbol>
Get list of available strategies
73 74 75 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 73 def available_strategies @strategies.keys end |
#disable! ⇒ Object
Disable authentication (return to pass-through mode)
26 27 28 29 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 26 def disable! @enabled = false @default_strategy = nil end |
#enable!(default_strategy: :api_key) ⇒ Object
Enable authentication with optional default strategy
20 21 22 23 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 20 def enable!(default_strategy: :api_key) @enabled = true @default_strategy = default_strategy end |
#remove_strategy(name) ⇒ Object
Remove an authentication strategy
40 41 42 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 40 def remove_strategy(name) @strategies.delete(name) end |
#required? ⇒ Boolean
Check if authentication is required
67 68 69 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 67 def required? @enabled end |