Class: VectorMCP::Security::Strategies::Custom

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

Instance Method Summary collapse

Constructor Details

#initialize(&handler) ⇒ Custom

Initialize with a custom authentication handler

Parameters:

  • handler (Proc)

    a block that takes a request and returns user info or false

Raises:

  • (ArgumentError)


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

#handlerObject (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, false

Authenticate a request using the custom handler

Parameters:

  • request (Hash)

    the request object

Returns:

  • (Object, false)

    result from custom handler or false if authentication failed



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vector_mcp/security/strategies/custom.rb', line 22

def authenticate(request)
  result = @handler.call(request)

  # Ensure result includes strategy info if it's successful
  if result && result != false
    format_successful_result(result)
  else
    false
  end
rescue NoMemoryError, StandardError
  # Log error but return false for security
  false
end

#configured?Boolean

Check if handler is configured

Returns:

  • (Boolean)

    true if handler is present



38
39
40
# File 'lib/vector_mcp/security/strategies/custom.rb', line 38

def configured?
  !@handler.nil?
end