Table of Contents

Class GoogleCloudAdcAuthenticator

Namespace
GenerativeAI.Authenticators
Assembly
GenerativeAI.dll

Provides a mechanism for authenticating with Google Cloud services using Application Default Credentials (ADC).

public class GoogleCloudAdcAuthenticator : BaseAuthenticator, IGoogleAuthenticator
Inheritance
GoogleCloudAdcAuthenticator
Implements
Inherited Members
Extension Methods

Remarks

This class enables accessing Google Cloud resources by utilizing credentials specified in the environment or through a supplied credential file. It implements the BaseAuthenticator abstract class and provides methods to acquire and refresh access tokens.

Constructors

GoogleCloudAdcAuthenticator(string?, ILogger?)

Represents an authenticator that uses Google Cloud Application Default Credentials (ADC) to acquire access tokens for authentication in Google Cloud environments.

public GoogleCloudAdcAuthenticator(string? credentialFile = null, ILogger? logger = null)

Parameters

credentialFile string
logger ILogger

Remarks

This authenticator leverages the ADC mechanism, optionally utilizing a provided credentials file, to handle authentication processes such as generating and refreshing access tokens. It integrates with Google's authentication environment.

Methods

GetAccessTokenAsync(CancellationToken)

Retrieves an access token for the Google API.

public override Task<AuthTokens?> GetAccessTokenAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<AuthTokens>

An instance of AuthTokens representing the access token.

RefreshAccessTokenAsync(AuthTokens, CancellationToken)

Refreshes an expired access token to obtain a new one.

public override Task<AuthTokens?> RefreshAccessTokenAsync(AuthTokens token, CancellationToken cancellationToken = default)

Parameters

token AuthTokens

The expired AuthTokens instance.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<AuthTokens>

An instance of AuthTokens representing the refreshed access token.