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, ...

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.

Parameters:

  • request (Hash)

    the request object

Returns:

  • (Object, nil, false)

    user data or false if authentication failed. A return of nil (from { user: nil }) signals “authenticated, no user object.”



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

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