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
cancellationTokenCancellationTokenA 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
tokenstringThe 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
tokenAuthTokensThe expired AuthTokens instance.
cancellationTokenCancellationTokenA 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
accessTokenstringThe access token to validate.
throwErrorboolIf true, throws an exception for an invalid token. Defaults to true.
cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Returns
- Task<AuthTokens>
A valid AuthTokens instance if the token is valid, or null if invalid and
throwErroris false.
Exceptions
- ArgumentNullException
Thrown if
accessTokenis null or empty.- AuthenticationException
Thrown if the token is invalid and
throwErroris true.