Documentation
¶
Overview ¶
Package gemini provides authentication and token management functionality for Google's Gemini AI services. It handles OAuth2 token storage, serialization, and retrieval for maintaining authenticated sessions with the Gemini API.
Package gemini provides authentication and token management functionality for Google's Gemini AI services. It handles OAuth2 authentication flows, including obtaining tokens via web-based authorization, storing tokens, and refreshing them when they expire.
Package gemini provides authentication and token management functionality for Google's Gemini AI services. It handles OAuth2 token storage, serialization, and retrieval for maintaining authenticated sessions with the Gemini API.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GeminiAuth ¶
type GeminiAuth struct { }
GeminiAuth provides methods for handling the Gemini OAuth2 authentication flow. It encapsulates the logic for obtaining, storing, and refreshing authentication tokens for Google's Gemini AI services.
func NewGeminiAuth ¶
func NewGeminiAuth() *GeminiAuth
NewGeminiAuth creates a new instance of GeminiAuth.
func (*GeminiAuth) GetAuthenticatedClient ¶
func (g *GeminiAuth) GetAuthenticatedClient(ctx context.Context, ts *GeminiTokenStorage, cfg *config.Config, noBrowser ...bool) (*http.Client, error)
GetAuthenticatedClient configures and returns an HTTP client ready for making authenticated API calls. It manages the entire OAuth2 flow, including handling proxies, loading existing tokens, initiating a new web-based OAuth flow if necessary, and refreshing tokens.
Parameters:
- ctx: The context for the HTTP client
- ts: The Gemini token storage containing authentication tokens
- cfg: The configuration containing proxy settings
- noBrowser: Optional parameter to disable browser opening
Returns:
- *http.Client: An HTTP client configured with authentication
- error: An error if the client configuration fails, nil otherwise
type GeminiTokenStorage ¶
type GeminiTokenStorage struct { // Token holds the raw OAuth2 token data, including access and refresh tokens. Token any `json:"token"` // ProjectID is the Google Cloud Project ID associated with this token. ProjectID string `json:"project_id"` // Email is the email address of the authenticated user. Email string `json:"email"` // Auto indicates if the project ID was automatically selected. Auto bool `json:"auto"` // Checked indicates if the associated Cloud AI API has been verified as enabled. Checked bool `json:"checked"` // Type indicates the authentication provider type, always "gemini" for this storage. Type string `json:"type"` }
GeminiTokenStorage stores OAuth2 token information for Google Gemini API authentication. It maintains compatibility with the existing auth system while adding Gemini-specific fields for managing access tokens, refresh tokens, and user account information.
func (*GeminiTokenStorage) SaveTokenToFile ¶
func (ts *GeminiTokenStorage) SaveTokenToFile(authFilePath string) error
SaveTokenToFile serializes the Gemini token storage to a JSON file. This method creates the necessary directory structure and writes the token data in JSON format to the specified file path for persistent storage.
Parameters:
- authFilePath: The full path where the token file should be saved
Returns:
- error: An error if the operation fails, nil otherwise
type GeminiWebTokenStorage ¶ added in v5.2.1
type GeminiWebTokenStorage struct { Secure1PSID string `json:"secure_1psid"` Secure1PSIDTS string `json:"secure_1psidts"` Type string `json:"type"` }
GeminiWebTokenStorage stores cookie information for Google Gemini Web authentication.
func (*GeminiWebTokenStorage) SaveTokenToFile ¶ added in v5.2.1
func (ts *GeminiWebTokenStorage) SaveTokenToFile(authFilePath string) error
SaveTokenToFile serializes the Gemini Web token storage to a JSON file.