Table of Contents

Class BaseAuthenticator

Namespace
GenerativeAI.Authenticators
Assembly
GenerativeAI.dll

An abstract base class for implementing authenticators for Google APIs.

public abstract class BaseAuthenticator : IGoogleAuthenticator
Inheritance
BaseAuthenticator
Implements
Derived
Inherited Members
Extension Methods

Methods

GetAccessTokenAsync(CancellationToken)

Retrieves an access token for the Google API.

public virtual 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.

GetTokenInfo(string)

Retrieves token information for the given access token by querying Google's token info endpoint.

protected static Task<AuthTokens?> GetTokenInfo(string token)

Parameters

token string

The access token to retrieve information for.

Returns

Task<AuthTokens>

A valid AuthTokens instance with the token data if successful, or null if unsuccessful.

RefreshAccessTokenAsync(AuthTokens, CancellationToken)

Refreshes an expired access token to obtain a new one.

public virtual 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.

ValidateAccessTokenAsync(string, bool, CancellationToken)

Validates the provided access token and determines its validity.

public Task<AuthTokens?> ValidateAccessTokenAsync(string accessToken, bool throwError = true, CancellationToken cancellationToken = default)

Parameters

accessToken string

The access token to validate.

throwError bool

If true, throws an exception for an invalid token. Defaults to true.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<AuthTokens>

A valid AuthTokens instance if the token is valid, or null if invalid and throwError is false.

Exceptions

ArgumentNullException

Thrown if accessToken is null or empty.

AuthenticationException

Thrown if the token is invalid and throwError is true.