Class: VectorMCP::Security::AuthManager

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeAuthManager

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_strategyObject (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

#enabledObject (readonly)

Returns the value of attribute enabled.



10
11
12
# File 'lib/vector_mcp/security/auth_manager.rb', line 10

def enabled
  @enabled
end

#strategiesObject (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

Parameters:

  • name (Symbol)

    the strategy name

  • strategy (Object)

    the strategy instance



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

Parameters:

  • request (Hash)

    the request object containing headers, params, etc.

  • strategy (Symbol) (defaults to: nil)

    optional strategy override

Returns:



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_strategiesArray<Symbol>

Get list of available strategies

Returns:

  • (Array<Symbol>)

    array of strategy names



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

Parameters:

  • default_strategy (Symbol) (defaults to: :api_key)

    the default authentication strategy to use



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

Parameters:

  • name (Symbol)

    the strategy name to remove



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

Returns:

  • (Boolean)

    true if authentication is enabled



67
68
69
# File 'lib/vector_mcp/security/auth_manager.rb', line 67

def required?
  @enabled
end