Defines the interface for access token generators.
Instances of this class can generate OAuth2 access tokens. These are used to authenticate with Google Cloud Platform (and other Google Services), and may be useful for applications that directly invoke REST-based services.
Performance
Creating a new access token is relatively expensive. It may require remote calls via HTTP, or at the very least some (local) cryptographic operations.
Most implementations of this class will cache an access token until it is about to expire. Application developers are advised to keep AccessTokenGenerator instances for as long as possible. They should also avoid caching the access token themselves, as caching is already provided by the implementation.
Thread Safety
It is safe to call an instance of this class from two separate threads.
Error Handling
This class uses StatusOr<T> to report errors. When an operation fails to perform its work the returned StatusOr<T> contains the error details. If the ok() member function in the StatusOr<T> returns true then it contains the expected result. Please consult the google::cloud::StatusOr documentation for more details.
Functions
GetToken()
Returns an OAuth2 access token.
This function caches the access token to avoid the cost of recomputing the token on each call.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[[["\u003cp\u003eThe page documents the \u003ccode\u003eAccessTokenGenerator\u003c/code\u003e class, which is used to generate OAuth2 access tokens for authenticating with Google Cloud Platform and other Google services.\u003c/p\u003e\n"],["\u003cp\u003eThis class caches access tokens to minimize the computational expense, which can involve remote HTTP calls or cryptographic operations, making it important for application developers to maintain \u003ccode\u003eAccessTokenGenerator\u003c/code\u003e instances as long as possible.\u003c/p\u003e\n"],["\u003cp\u003eIt is thread-safe to call an instance of \u003ccode\u003eAccessTokenGenerator\u003c/code\u003e from multiple threads.\u003c/p\u003e\n"],["\u003cp\u003eThe class uses \u003ccode\u003eStatusOr<T>\u003c/code\u003e to manage errors, with \u003ccode\u003eok()\u003c/code\u003e confirming successful operation and the object containing error details if operation is unsuccessful.\u003c/p\u003e\n"],["\u003cp\u003eThe page provides a version history of the class, starting from version 2.16.0 up to the latest release candidate version 2.37.0-rc, and each version is linked to its respective documentation.\u003c/p\u003e\n"]]],[],null,[]]