Token types  |  Authentication  |  Google Cloud (2024)

This page discusses the types of tokens used for authentication to Google APIs,Google Cloud services, and customer-created services hosted on Google Cloud.

If you are accessing Google APIs and services byusing a client library, you canset up Application Default Credentials, and the client libraryhandles tokens for you. This is the recommended approach.

What tokens are

For authentication and authorization, a token is a digital object that containsinformation about the identity of the principal making the request and what kindof access they are authorized for. In most authentication flows, theapplication—or a library used by the application—exchanges acredential for a token, which determines which resources the application isauthorized to access.

Types of tokens

Different types of tokens are used in different environments. The followingtoken types are described on this page:

  • Access tokens
  • ID tokens
  • Self-signed JWTs
  • Refresh tokens
  • Federated tokens
  • Bearer tokens

This page does not discuss API keys or Client IDs,which are considered credentials.

Access tokens

Access tokens are opaque tokens that conform to theOAuth 2.0 framework. They contain authorizationinformation, but not identity information. They are used to authenticate andprovide authorization information to Google APIs.

If you use Application Default Credentials (ADC) and theCloud Client Libraries or Google API Client Libraries, you do not needto manage access tokens; the libraries automatically retrieve the credential,exchange it for an access token, and refresh the access token as needed.

Access token contents

Access tokens are opaque tokens, which means that they are in a proprietaryformat; applications cannot inspect them. You can get the information from avalid (not expired or revoked) access token by using the Google OAuth 2.0tokeninfo endpoint.

Replace ACCESS_TOKEN with the valid, unexpired access token.

curl "https://oauth2.googleapis.com/tokeninfo?access_token=ACCESS_TOKEN"

This command returns something similar to the following example:

{ "azp": "32553540559.apps.googleusercontent.com", "aud": "32553540559.apps.googleusercontent.com", "sub": "111260650121245072906", "scope": "openid https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/accounts.reauth", "exp": "1650056632", "expires_in": "3488", "email": "[email protected]", "email_verified": "true"}

The following table lists the most important fields to understand:

Field Description
azp The project, email, or service account ID of the application that requested the token. This value is included only if https://www.googleapis.com/auth/userinfo.email is specified in the list of scopes.
scope The OAuth scopes that have been added to this access token. For Google Cloud services, it is a best practice to use the https://www.googleapis.com/auth/cloud-platform scope, which includes all Google Cloud APIs, together with Identity and Access Management (IAM), which provides fine-grained access control.
expires_in The number of seconds until the token expires. For more information, see Access token lifetime.

Access token lifetime

By default, access tokens are good for 1 hour(3,600 seconds). When the access token hasexpired, your token management code must get a new one.

If you need an access token with a longer or shorter lifetime, you can use theserviceAccounts.generateAccessToken methodto create the token. This method enables you to choose the lifetime of thetoken, with a maximum lifetime of 12 hours.

If you want to extend the token lifetime beyond the default, you must create anorganization policy that enables the iam.allowServiceAccountCredentialLifetimeExtensionconstraint. You can't create access tokens with an extendedlifetime for user credentials or external identities. For more information, seeCreate a short-lived access token.

ID tokens

ID tokens are JSON Web Tokens (JWTs) that conform tothe OpenID Connect (OIDC) specification. They arecomposed of a set of key-value pairs called claims.

Unlike access tokens, which are opaque objects that cannot be inspected by theapplication, ID tokens are meant to be inspected and used by the application.Information from the token, such as Who signed the token or the identity forwhom the ID token was issued, is available for use by the application.

For more information about Google’s OIDC implementation, seeOpenID Connect. For best practices for working with JWTs, seeJSON Web Token Best Current Practices.

ID token contents

You can inspect a valid (not expired or revoked) ID token by using the GoogleOAuth 2.0 tokeninfo endpoint.

Replace ID_TOKEN with the valid, unexpired ID token.

curl "https://oauth2.googleapis.com/tokeninfo?id_token=ID_TOKEN"

This command returns something similar to the following example:

{ "iss": "https://accounts.google.com", "azp": "32555350559.apps.googleusercontent.com", "aud": "32555350559.apps.googleusercontent.com", "sub": "111260650121185072906", "hd": "google.com", "email": "[email protected]", "email_verified": "true", "at_hash": "_LLKKivfvfme9eoQ3WcMIg", "iat": "1650053185", "exp": "1650056785", "alg": "RS256", "kid": "f1338ca26835863f671403941738a7b49e740fc0", "typ": "JWT"}

The following table describes required or commonly used ID token claims:

Claim Description
iss The issuer, or signer, of the token. For Google-signed ID tokens, this value is https://accounts.google.com.
azp Optional. Who the token was issued to.
aud The audience of the token. The value of this claim must match the application or service that uses the token to authenticate the request. For more information, see ID token aud claim.
sub The subject: the ID that represents the principal making the request.
iat Unix epoch time when the token was issued.
exp Unix epoch time when the token expires.

Other claims might be present, depending on the issuer and the application.

ID token aud claim

The aud claim describes the service name this token was created to invoke.If a service receives an ID token, it must verify its integrity (signature),validity (is it expired) and if the aud claim matches the name it expects.If it does not match, the service should reject the token, because it could bea replay intended for another system.

Generally, when you get an ID token, you use the credentialsprovided by a service account, rather than user credentials. This is because theaud claim for ID tokens generated using user credentials is statically boundto the application the user used to authenticate. When you use a service accountto acquire an ID token, you can specify a different value for the aud claim.

ID token lifetime

ID tokens are valid for up to 1 hour(3,600 seconds).When an ID token expires, you must acquire a new one.

ID token validation

When your service or application uses a Google service such asCloud Run, Cloud Functions, or Identity-Aware Proxy, Google validates IDtokens for you; in these cases, the ID tokens must be signed by Google.

If you need to validate ID tokens within your application, you can do so,although this is an advanced workflow. For information, seeValidating an ID token.

Self-signed JSON Web Tokens (JWTs)

Self-signed JWTs are required toauthenticate to APIs deployed with API Gateway. Inaddition, you can use self-signed JWTs to authenticate to some Google APIswithout having to get an access token from the Authorization Server.

Creating self-signed JWTs is recommended if you are creating your own clientlibraries to access Google APIs, but is an advanced workflow. For moreinformation about self-signed JWTs, seeCreating a self-signed JSON Web Token.For best practices for working with JWTs, seeJSON Web Token Best Current Practices.

Refresh tokens

By default, access tokens and ID tokens are valid for1 hour. A refresh token is a special token that is usedto obtain additional access tokens or ID tokens. When your application firstauthenticates, it receives an access token or ID token, as well as a refreshtoken. Later, if the application needs to access resources again, and thepreviously provided token has expired, it uses the refresh token to request anew token. Refresh tokens are used only for user authentication,such as for Cloud Identity or Google Workspace.

Refresh tokens don't have a set lifetime; they can expire, butotherwise they continue to be usable. For user access in Google Workspace orCloud Identity premium edition, you canconfigure the session length to ensure that a user must login periodically to retain access to Google Cloud services.

If your application is creating and managing its own tokens, it also needs tomanage refresh tokens. For more information, see the following links:

  • OAuth 2.0 for Server to Server Applications
  • OAuth 2.0 for Web Server Applications.
  • OAuth 2.0 for Client-side Web Applications
  • OAuth 2.0 for TV and Limited-Input Device Applications

Federated tokens

Federated tokens are used as an intermediate step byworkload identity federation. Federated tokens are returned by theSecurity Token Service and cannot be used directly. They must beexchanged for an access token using service accountimpersonation.

Bearer tokens

Bearer tokens are a general class of token that grants access to theparty in possession of the token. Access tokens, ID tokens, and self-signed JWTsare all bearer tokens.

Using bearer tokens for authentication relies on the security provided byan encrypted protocol, such as HTTPS; if a bearer token is intercepted, it canbe used by a bad actor to gain access.

If bearer tokens don’t provide sufficient security for your use case, consideradding another layer of encryption or using a mutual Transport Layer Security(mTLS) solution such as BeyondCorp Enterprise, which limits access to onlyauthenticated users on a trusted device.

What's next

  • Learn how to set up credentials for ADC.
  • See information aboutgetting ID tokens.
  • Review authentication use cases.
  • Understand more about authentication at Google.

I'm an expert in authentication and authorization mechanisms, particularly regarding token-based security models within the context of Google APIs and Google Cloud services. My expertise stems from years of practical experience in designing, implementing, and troubleshooting authentication systems across various environments.

Authentication tokens are digital objects crucial for validating the identity of an entity making a request and specifying the level of access it possesses. In the realm of Google APIs and services, several types of tokens are utilized, each serving distinct purposes:

  1. Access tokens: These opaque tokens conform to the OAuth 2.0 framework, containing authorization but not identity information. They are used to authenticate and provide authorization details to Google APIs.

  2. ID tokens: JSON Web Tokens (JWTs) adhering to the OpenID Connect (OIDC) specification. Unlike access tokens, ID tokens are meant to be inspected and utilized by applications, providing information about the issuer, audience, subject, and expiration time.

  3. Self-signed JWTs: These are essential for authenticating to APIs deployed with API Gateway and certain Google APIs without requiring an access token from the Authorization Server. They're recommended for creating custom client libraries accessing Google APIs.

  4. Refresh tokens: Special tokens used to obtain additional access or ID tokens when the initially provided tokens expire. They are specifically employed for user authentication, such as Cloud Identity or Google Workspace.

  5. Federated tokens: Intermediary tokens in workload identity federation, obtained from the Security Token Service. They require exchange for an access token using service account impersonation.

  6. Bearer tokens: A broad category encompassing access tokens, ID tokens, and self-signed JWTs. These tokens grant access to the possessor, and their security relies on encrypted protocols like HTTPS.

These tokens serve different purposes and have varying lifetimes. Access tokens and ID tokens typically last for one hour, while refresh tokens persist until their expiration or revocation.

Understanding and managing these tokens are crucial for secure access to Google APIs and services. Utilizing appropriate token types and their associated endpoints (like tokeninfo) helps in validating, inspecting, and managing these tokens effectively for robust authentication and authorization practices.

Token types  |  Authentication  |  Google Cloud (2024)

FAQs

What are the different types of tokens in OIDC? ›

This topic presents an overview of the two types of tokens in OpenID Connect: ID tokens and access tokens. These tokens can be used to gain access to users' information and to protected resources on behalf of the users.

What is access token and ID token? ›

They can both be encoded as JWT, but the content and purpose are also different. An ID token contains the identity information about the authenticated users, and it is intended to be consumed by the front-end application. On the other hand, an access token represents a ticket with permission to consume an API.

Does Google OAuth use JWT? ›

After you obtain the client ID and private key from the API Console, your application needs to complete the following steps: Create a JSON Web Token (JWT, pronounced, "jot") which includes a header, a claim set, and a signature. Request an access token from the Google OAuth 2.0 Authorization Server.

What is a cloud token? ›

Cloud Token Framework (CTF) allows the entire payment ecosystem to minimize risks associated with managing sensitive payment data. CTF enables card-not-present (CNP) tokens to unlock new opportunities in digital commerce and accelerate payment innovation.

What is SAML vs OIDC? ›

The main difference between SAML and OIDC is that SAML builds the trust relationship between the service provider (SP) and the IdP, whereas OIDC trusts the channel (HTTPS) that is used to obtain the security token.

Which is more secure, JWT or OAuth? ›

Security: OAuth is a secure way to manage authorization flows, while JWT is a lightweight and self-contained token. It does not provide security on its own, but can be secure as part of a well designed authentication system.

What is the difference between OpenID and JWT? ›

OpenID is designed for authentication, enabling users to authenticate using an existing account with an OpenID provider. JWT, on the other hand, is used for stateless authentication and authorization, particularly in web applications that use RESTful APIs.

What type of token is JWT? ›

JSON Web Token (JWT) is a compact claims representation format that is intended for space constrained environments such as HTTP Authorization headers and URI query parameters. A claim is represented as a name-value pair that contains a Claim Name and a Claim Value.

What is the difference between OpenID and oauth2? ›

OpenID is an authentication protocol used for signing users into client applications. The purpose is user authentication. OAuth is an authorization protocol used for providing client applications delegated access to server resources on behalf of a user. The purpose is delegated authorization.

What is API key or access token? ›

The main distinction between these two is: API keys identify the calling project — the application or site — making the call to an API. Authentication tokens identify a user — the person — that is using the app or site.

Does AWS use JWT? ›

You can use the console, the AWS CLI, or an AWS SDK to update a route to use a JWT authorizer.

Why use JWT instead of basic auth? ›

JWT is preferred over any other authentication method because of certain distinct benefits it presents. Developers opt for JWT as these tokens are self-contained and don't ask for any effort to collect info about the user.

Is JWT more secure than API key? ›

The credentials can either be a cryptographically secure JSON Web Token (JWT) signed with the client's private key or a secret value generated from your authorization server. A private key JWT is more secure, as you won't risk exposing the secret value that accidentally creates similar access concerns as an API key.

What is an example of a token? ›

a memento; souvenir; keepsake: The seashell was a token of their trip. something used to indicate authenticity, authority, etc.; emblem; badge: Judicial robes are a token of office.

What are the classification of tokens? ›

Token classification involves labelling each token with a specific category based on its meaning or function in the text. For example, in a sentence, verbs can be labelled as "VERB", nouns as "NOUN", adjectives as "ADJECTIVE", and so on.

What is the difference between coin and token? ›

Coins are digital assets that operate on their own independent blockchain. Tokens are digital assets that operate on an existing blockchain network. While coins primarily function as a medium of exchange, tokens aim to offer a wider range of functionalities within a specific project's ecosystem.

Are tokens worth any money? ›

Unlike commodity money, which is worth its weight in gold or silver, one definition of tokens is that they are a medium of exchange that is worth more than whatever they're made of. The token is not supposed to be valuable for what it is in itself but because of what it represents.

Top Articles
EliteMarketMovers : FOREX - BTCUSD FORECAST TODAY
Calculate your car insurance - KBC Brussels Bank & Insurance
Exclusive: Baby Alien Fan Bus Leaked - Get the Inside Scoop! - Nick Lachey
Star Sessions Imx
The UPS Store | Ship & Print Here > 400 West Broadway
Beacon Schnider
Tyrunt
Kris Carolla Obituary
Craigslist - Pets for Sale or Adoption in Zeeland, MI
Meg 2: The Trench Showtimes Near Phoenix Theatres Laurel Park
Visustella Battle Core
Seafood Bucket Cajun Style Seafood Restaurant in South Salt Lake - Restaurant menu and reviews
Gfs Rivergate
Johnston v. State, 2023 MT 20
Https E24 Ultipro Com
Bjork & Zhulkie Funeral Home Obituaries
Radio Aleluya Dialogo Pastoral
Mary Kay Lipstick Conversion Chart PDF Form - FormsPal
Sam's Club La Habra Gas Prices
Tygodnik Polityka - Polityka.pl
Vipleaguenba
Ubg98.Github.io Unblocked
Grimes County Busted Newspaper
Nsa Panama City Mwr
Bellin Patient Portal
1 Filmy4Wap In
Myql Loan Login
Accuradio Unblocked
Vlacs Maestro Login
WOODSTOCK CELEBRATES 50 YEARS WITH COMPREHENSIVE 38-CD DELUXE BOXED SET | Rhino
Shauna's Art Studio Laurel Mississippi
October 19 Sunset
Emiri's Adventures
Roch Hodech Nissan 2023
Plato's Closet Mansfield Ohio
Linabelfiore Of
Clark County Ky Busted Newspaper
Hebrew Bible: Torah, Prophets and Writings | My Jewish Learning
Craigslist Mexicali Cars And Trucks - By Owner
A Comprehensive 360 Training Review (2021) — How Good Is It?
FREE - Divitarot.com - Tarot Denis Lapierre - Free divinatory tarot - Your divinatory tarot - Your future according to the cards! - Official website of Denis Lapierre - LIVE TAROT - Online Free Tarot cards reading - TAROT - Your free online latin tarot re
Frigidaire Fdsh450Laf Installation Manual
Chubbs Canton Il
La Qua Brothers Funeral Home
Displacer Cub – 5th Edition SRD
Here’s What Goes on at a Gentlemen’s Club – Crafternoon Cabaret Club
Craigslist Anc Ak
Lux Funeral New Braunfels
Wwba Baseball
Tenichtop
Ranking 134 college football teams after Week 1, from Georgia to Temple
Latest Posts
Article information

Author: The Hon. Margery Christiansen

Last Updated:

Views: 6450

Rating: 5 / 5 (50 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: The Hon. Margery Christiansen

Birthday: 2000-07-07

Address: 5050 Breitenberg Knoll, New Robert, MI 45409

Phone: +2556892639372

Job: Investor Mining Engineer

Hobby: Sketching, Cosplaying, Glassblowing, Genealogy, Crocheting, Archery, Skateboarding

Introduction: My name is The Hon. Margery Christiansen, I am a bright, adorable, precious, inexpensive, gorgeous, comfortable, happy person who loves writing and wants to share my knowledge and understanding with you.