pub async fn create_access_token_credential() -> Result<Credential, CredentialError>Expand description
Create access token credentials.
Returns Application Default Credentials (ADC). These are the most commonly used credentials, and are expected to meet the needs of most applications. They conform to AIP-4110.
The access tokens returned by these credentials are to be used in the
Authorization HTTP header.
Consider using these credentials when:
- Your application is deployed to a Google Cloud environment such as Google Compute Engine (GCE), Google Kubernetes Engine (GKE), or Cloud Run. Each of these deployment environments provides a default service account to the application, and offers mechanisms to change this default service account without any code changes to your application.
- You are testing or developing the application on a workstation (physical or virtual). These credentials will use your preferences as set with gcloud auth application-default. These preferences can be your own GCP user credentials, or some service account.
- Regardless of where your application is running, you can use the
GOOGLE_APPLICATION_CREDENTIALSenvironment variable to override the defaults. This environment variable should point to a file containing a service account key file, or a JSON object describing your user credentials.
Example usage:
let mut creds = create_access_token_credential().await?;
let token = creds.get_token().await?;
println!("Token: {}", token.token);