gcloud auth print-access-token

NAME
gcloud auth print-access-token - print an access token for the specified account
SYNOPSIS
gcloud auth print-access-token[ACCOUNT][--lifetime=LIFETIME][GCLOUD_WIDE_FLAG]
DESCRIPTION
Print an access token for the specified account. SeeRFC6749 for more informationabout access tokens.

Note that token itself may not be enough to access some services. If you use thetoken with curl or similar tools, you may see permission errors similar to "APIhas not been used in project 32555940559 before or it is disabled.". If ithappens, you may need to provide a quota project in the "X-Goog-User-Project"header. For example,

curl-H"X-Goog-User-Project: your-project"-H"Authorization: Bearer$(gcloudauthprint-access-token)"foo.googleapis.com

The identity that granted the token must have the serviceusage.services.usepermission on the provided project. Seehttps://cloud.google.com/apis/docs/system-parametersfor more information.

EXAMPLES
To print access tokens:
gcloudauthprint-access-token
POSITIONAL ARGUMENTS
[ACCOUNT]
Account to get the access token for. If not specified, the current activeaccount will be used.
FLAGS
--lifetime=LIFETIME
Access token lifetime. The default access token lifetime is 3600 seconds, butyou can use this flag to reduce the lifetime or extend it up to 43200 seconds(12 hours). The org policy constraintconstraints/iam.allowServiceAccountCredentialLifetimeExtension mustbe set if you want to extend the lifetime beyond 3600 seconds. Note that thisflag is for service account impersonation only, so it must be used together withthe--impersonate-service-account flag.
GCLOUD WIDE FLAGS
These flags are available to all commands:--access-token-file,--account,--billing-project,--configuration,--flags-file,--flatten,--format,--help,--impersonate-service-account,--log-http,--project,--quiet,--trace-token,--user-output-enabled,--verbosity.

Run$gcloud help for details.

NOTES
These variants are also available:
gcloudalphaauthprint-access-token
gcloudbetaauthprint-access-token

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-05-07 UTC.