Gemini.Auth.MultiAuthCoordinator (GeminiEx v0.0.2)
View SourceCoordinates 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
@type auth_result() :: {:ok, auth_strategy(), headers :: list()} | {:error, term()}
@type auth_strategy() :: :gemini | :vertex_ai
@type credentials() :: map()
@type request_opts() :: keyword()
@type t() :: %Gemini.Auth.MultiAuthCoordinator{}
Functions
@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"])
@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 strategyopts
: Optional configuration overrides
Returns
{:ok, credentials}
on success{:error, reason}
on failure
@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
@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