Gemini.Auth (GeminiEx v0.0.1)

View Source

Authentication strategy behavior and implementations for Gemini and Vertex AI.

This module provides a unified interface for different authentication methods:

  • Gemini API: Simple API key authentication
  • Vertex AI: OAuth2/Service Account authentication

Summary

Functions

Authenticate using the given strategy and configuration.

Get base URL using the given strategy and configuration.

Build authenticated headers for the given strategy and credentials.

Build the full path for an API endpoint.

Get the base URL for the given strategy and credentials.

Get the appropriate authentication strategy based on configuration.

Refresh credentials if needed (mainly for Vertex AI OAuth tokens).

Get the appropriate authentication strategy based on configuration. (Alias for get_strategy/1 for backward compatibility)

Types

auth_type()

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

credentials()

@type credentials() ::
  %{api_key: String.t()}
  | %{access_token: String.t(), project_id: String.t(), location: String.t()}

Functions

authenticate(strategy_module, config)

@spec authenticate(module(), map()) :: {:ok, map()} | {:error, term()}

Authenticate using the given strategy and configuration.

base_url(strategy_module, config)

@spec base_url(module(), map()) :: String.t() | {:error, term()}

Get base URL using the given strategy and configuration.

build_headers(auth_type, credentials)

@spec build_headers(auth_type(), map()) :: [{String.t(), String.t()}]

Build authenticated headers for the given strategy and credentials.

build_path(auth_type, model, endpoint, credentials)

@spec build_path(auth_type(), String.t(), String.t(), map()) :: String.t()

Build the full path for an API endpoint.

get_base_url(auth_type, credentials)

@spec get_base_url(auth_type(), map()) :: String.t() | {:error, term()}

Get the base URL for the given strategy and credentials.

get_strategy(auth_type)

@spec get_strategy(auth_type()) :: module()

Get the appropriate authentication strategy based on configuration.

refresh_credentials(auth_type, credentials)

@spec refresh_credentials(auth_type(), map()) :: {:ok, map()} | {:error, term()}

Refresh credentials if needed (mainly for Vertex AI OAuth tokens).

strategy(auth_type)

@spec strategy(auth_type()) :: module()

Get the appropriate authentication strategy based on configuration. (Alias for get_strategy/1 for backward compatibility)