Gemini.Auth.MultiAuthCoordinator (GeminiEx v0.0.1)

View Source

Coordinates multiple authentication strategies for concurrent usage.

Enables per-request auth strategy selection while maintaining independent credential management and request routing.

This module serves as the central coordination point for the Gemini Unified Implementation's multi-auth capability, allowing applications to use both Gemini API and Vertex AI authentication strategies simultaneously.

Summary

Functions

Coordinates authentication for the specified strategy.

Retrieves credentials for the specified authentication strategy.

Refreshes credentials for the specified authentication strategy.

Validates configuration for the specified authentication strategy.

Types

auth_result()

@type auth_result() :: {:ok, auth_strategy(), headers :: list()} | {:error, term()}

auth_strategy()

@type auth_strategy() :: :gemini | :vertex_ai

credentials()

@type credentials() :: map()

request_opts()

@type request_opts() :: keyword()

t()

@type t() :: %Gemini.Auth.MultiAuthCoordinator{}

Functions

coordinate_auth(strategy, opts \\ [])

@spec coordinate_auth(auth_strategy(), request_opts()) :: auth_result()

Coordinates authentication for the specified strategy.

This is the main entry point for multi-auth coordination. It routes authentication requests to the appropriate strategy while maintaining independent credential management.

Parameters

  • strategy: The authentication strategy (:gemini or :vertex_ai)
  • opts: Request options (may include configuration overrides)

Returns

  • {:ok, strategy, headers} on successful authentication
  • {:error, reason} on authentication failure

Examples

# Coordinate Gemini API authentication
{:ok, :gemini, headers} = MultiAuthCoordinator.coordinate_auth(:gemini, [])

# Coordinate Vertex AI authentication
{:ok, :vertex_ai, headers} = MultiAuthCoordinator.coordinate_auth(:vertex_ai, [])

# With configuration overrides
{:ok, :gemini, headers} = MultiAuthCoordinator.coordinate_auth(:gemini, [api_key: "override"])

get_credentials(strategy, opts \\ [])

@spec get_credentials(auth_strategy(), request_opts()) ::
  {:ok, credentials()} | {:error, term()}

Retrieves credentials for the specified authentication strategy.

Loads credentials from configuration, with optional overrides from request options.

Parameters

  • strategy: The authentication strategy
  • opts: Optional configuration overrides

Returns

  • {:ok, credentials} on success
  • {:error, reason} on failure

refresh_credentials(strategy)

@spec refresh_credentials(auth_strategy()) :: {:ok, credentials()} | {:error, term()}

Refreshes credentials for the specified authentication strategy.

For strategies that support credential refresh (like Vertex AI OAuth tokens), this function will generate fresh credentials. For strategies that don't need refresh (like Gemini API keys), it returns the existing credentials.

Parameters

  • strategy: The authentication strategy

Returns

  • {:ok, refreshed_credentials} on success
  • {:error, reason} on failure

validate_auth_config(strategy)

@spec validate_auth_config(auth_strategy()) :: :ok | {:error, term()}

Validates configuration for the specified authentication strategy.

Checks that all required configuration is present and valid for the given strategy.

Parameters

  • strategy: The authentication strategy to validate

Returns

  • :ok if configuration is valid
  • {:error, reason} if configuration is invalid or missing