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) ⇒ Object, false
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.
10 11 12 13 14 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 10 def initialize @strategies = {} @enabled = false @default_strategy = nil end |
Instance Attribute Details
#default_strategy ⇒ Object (readonly)
Returns the value of attribute default_strategy.
8 9 10 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 8 def default_strategy @default_strategy end |
#enabled ⇒ Object (readonly)
Returns the value of attribute enabled.
8 9 10 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 8 def enabled @enabled end |
#strategies ⇒ Object (readonly)
Returns the value of attribute strategies.
8 9 10 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 8 def strategies @strategies end |
Instance Method Details
#add_strategy(name, strategy) ⇒ Object
Add an authentication strategy
32 33 34 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 32 def add_strategy(name, strategy) @strategies[name] = strategy end |
#authenticate(request, strategy: nil) ⇒ Object, false
Authenticate a request using the specified or default strategy
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 46 def authenticate(request, strategy: nil) return { authenticated: true, user: nil } unless @enabled strategy_name = strategy || @default_strategy auth_strategy = @strategies[strategy_name] return { authenticated: false, error: "Unknown strategy: #{strategy_name}" } unless auth_strategy begin result = auth_strategy.authenticate(request) if result { authenticated: true, user: result } else { authenticated: false, error: "Authentication failed" } end rescue StandardError => e { authenticated: false, error: "Authentication error: #{e.}" } end end |
#available_strategies ⇒ Array<Symbol>
Get list of available strategies
74 75 76 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 74 def available_strategies @strategies.keys end |
#disable! ⇒ Object
Disable authentication (return to pass-through mode)
24 25 26 27 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 24 def disable! @enabled = false @default_strategy = nil end |
#enable!(default_strategy: :api_key) ⇒ Object
Enable authentication with optional default strategy
18 19 20 21 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 18 def enable!(default_strategy: :api_key) @enabled = true @default_strategy = default_strategy end |
#remove_strategy(name) ⇒ Object
Remove an authentication strategy
38 39 40 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 38 def remove_strategy(name) @strategies.delete(name) end |
#required? ⇒ Boolean
Check if authentication is required
68 69 70 |
# File 'lib/vector_mcp/security/auth_manager.rb', line 68 def required? @enabled end |