Access Token Lifetime - OAuth 2.0 Simplified (2024)

When your service issues access tokens, you’ll need to make some decisions as to how long you want the tokens to last. Unfortunately there is no blanket solution for every service. There are various tradeoffs that come with the different options, so you should choose the option (or combination of options) that best suit your application’s need.

Short-lived access tokens and long-lived refresh tokens

A common method of granting tokens is to use a combination of access tokens and refresh tokens for maximum security and flexibility. The OAuth 2.0 spec recommends this option, and several of the larger implementations have gone with this approach.

Typically services using this method will issue access tokens that last anywhere from several hours to a couple weeks. When the service issues the access token, it also generates a refresh token that never expires and returns that in the response as well. (Note that refresh tokens can’t be issued using the Implicit grant.)

When the access token expires, the application can use the refresh token to obtain a new access token. It can do this behind the scenes, and without the user’s involvement, so that it’s a seamless process to the user.

The main benefit of this approach is that the service can use self-encoded access tokens which can be verified without a database lookup. However, this means there is no way to expire those tokens directly, so instead, the tokens are issued with a short expiration time so that the application is forced to continually refresh them, giving the service a chance to revoke an application’s access if needed.

From the third-party developer’s perspective, it is often frustrating to have to deal with refresh tokens. Developers strongly prefer access tokens that don’t expire, since it’s much less code to deal with. In order to help mitigate these concerns, services will often build the token refreshing logic into their SDK, so that the process is transparent to developers.

In summary, use short-lived access tokens and long-lived refresh tokens when:

  • you want to use self-encoded access tokens
  • you want to limit the risk of leaked access tokens
  • you will be providing SDKs that can handle the refresh logic transparently to developers

Short-lived access tokens and no refresh tokens

If you want to ensure users are aware of applications that are accessing their account, the service can issue relatively short-lived access tokens without refresh tokens. The access tokens may last anywhere from the current application session to a couple weeks. When the access token expires, the application will be forced to make the user sign in again, so that you as the service know the user is continually involved in re-authorizing the application.

Typically this option is used by services where there is a high risk of damage if a third-party application were to accidentally or maliciously leak access tokens. By requiring that users are constantly re-authorizing the application, the service can ensure that potential damage is limited if an attacker were to steal access tokens from the service.

By not issuing refresh tokens, this makes it impossible to applications to use the access token on an ongoing basis without the user in front of the screen. Applications that need access in order to continually sync data will be unable to do so under this method.

From the user’s perspective, this is the option most likely to frustrate people, since it will look like the user has to continually re-authorize the application.

In summary, use short-lived access tokens with no refresh tokens when:

  • you want to the most protection against the risk of leaked access tokens
  • you want to force users to be aware of third-party access they are granting
  • you don’t want third-party apps to have offline access to users’ data

Non-expiring access tokens

Non-expiring access tokens are the easiest method for developers. If you choose this option, it is important to consider the trade-offs you are making.

It isn’t practical to use self-encoded tokens if you want to be able to revoke them arbitrarily. As such, you’ll need to store these tokens in some sort of database, so they can be deleted or marked as invalid as needed.

Note that even if the service intends on issuing non-expiring access tokens for normal use, you’ll still need to provide a mechanism to expire them under exceptional circ*mstances, such as if the user explicitly wants to revoke an application’s access, or if a user account is deleted.

Non-expiring access tokens are much easier for developers testing their own applications. You can even pre-generate one or more non-expiring access tokens for developers and show it to them on the application details screen. This way they can immediately start making API requests with the token, and not worry about setting up an OAuth flow in order to start testing your API.

In summary, use non-expiring access tokens when:

  • you have a mechanism to revoke access tokens arbitrarily
  • you don’t have a huge risk if tokens are leaked
  • you want to provide an easy authentication mechanism to your developers
  • you want third-party applications to have offline access to users’ data
Access Token Lifetime - OAuth 2.0 Simplified (2024)

FAQs

What is access token lifetime? ›

Access tokens: varies, depending on the client application requesting the token. For example, continuous access evaluation (CAE) capable clients that negotiate CAE-aware sessions will see a long lived token lifetime (up to 28 hours). ID tokens, SAML2 tokens: 1 hour.

How long do OAuth2 tokens last? ›

By default, access tokens are valid for 60 days and programmatic refresh tokens are valid for a year. The member must reauthorize your application when refresh tokens expire.

What is the format for access token expiry time? ›

Use the property, SchedulerExecutionFrequency, to specify how frequently to check for the expiration status of access tokens. Enter the time interval in the following format: years (y), months (m), days (d), hours (h), minutes (min).

How do you extend the lifetime of OAuth 2.0 access tokens to up to 12 hours? ›

By default, the maximum lifetime of an access token is 1 hour (3,600 seconds). However, you can extend the maximum lifetime to 12 hours. To do so, identify the service accounts that need an extended lifetime for access tokens, then add these service accounts to an organization policy that includes the constraints/iam.

How do I keep my access token alive? ›

Keeping access tokens fresh and valid
  1. Use refresh tokens. Refresh tokens can be used by developers to obtain a newly-issed access token. ...
  2. Implement a separate process to keep tokens fresh. ...
  3. Avoid race conditions. ...
  4. Consider using JWT auth.
Jan 31, 2024

What happens after access token expires? ›

After expiration, the user gets a new refresh token in the same family, or refresh tokens that share a family ID, or a new access token/refresh token pair. To learn more, read Refresh Token Rotation.

What is the lifespan of refresh token vs access token? ›

Refresh tokens have a longer lifetime than access tokens. The default lifetime for the refresh tokens is 24 hours for single page apps and 90 days for all other scenarios. Refresh tokens replace themselves with a fresh token upon every use.

What is the difference between JWT and oauth2 tokens? ›

JWT token vs oauth token: JWT defines a token format while OAuth deals in defining authorization protocols. JWT is simple and easy to learn from the initial stage while OAuth is complex. OAuth uses both client-side and server-side storage while JWT must use only client-side storage. JWT has limited scope and use cases.

How to check OAuth token expiry? ›

More specifically, how do you know if it has already expired or not? When you obtain an access token, the JSON that comes back when you make a request includes another property in addition to the token itself. It's called expired_in and that is how long, in seconds, you have before the token expires.

How do you enforce maximum personal access token lifespan? ›

Set maximum lifespan for new PATs

Sign in to your organization ( https://dev.azure.com/{yourorganization} ). Organization settings. In the Microsoft Entra ID tab, find the Enforce maximum personal access token lifespan policy and move the toggle to on. Enter the number of maximum days, and then select Save.

How long is an access token to vault valid for? ›

If you do not explicitly set the token's TTL or maximum TTL, it takes the system max TTL which is 32 days by default. (You can change the system default in the Vault server configuration file.) This means that Vault stores the token in its storage backend for 32 days even if you are not using it.

How do I set my access token lifetime? ›

Configure access token lifetime
  1. Go to Dashboard > Applications > APIs and select the name of the API to view.
  2. Locate the Token Expiration field under Token Settings.
  3. Enter the desired lifetime (in seconds) for access tokens issued for this API. Default value is 86,400 seconds (24 hours). ...
  4. Select Save Changes.

What is the minimum access token lifetime? ›

Access and ID token lifetimes (minutes) - The lifetime of the OAuth 2.0 bearer token and ID tokens. The default is 60 minutes (1 hour). The minimum (inclusive) is 5 minutes. The maximum (inclusive) is 1,440 minutes (24 hours).

How long can an access token be? ›

By default, an access token for a custom API is valid for 86400 seconds (24 hours). We recommend that you set the validity period of your token based on the security requirements of your API. For example, an access token that accesses a banking API should expire more quickly than one that accesses a to-do API.

What is the lifespan of Google access token? ›

Access token lifetime

generateAccessToken method to create the token. This method enables you to choose the lifetime of the token, with a maximum lifetime of 12 hours. If you want to extend the token lifetime beyond the default, you must create an organization policy that enables the iam.

What is access token lifetime in Okta? ›

When you are using the Okta Authorization Server, the lifetime of the JWT tokens is hard-coded to the following values: ID token: 60 minutes. Access token: 60 minutes. Refresh token: 90 days.

What is access token used for? ›

Access Tokens can be either an opaque string or a JSON Web Token (JWT) . They inform the API that the bearer of the token has been authorized: to access a particular service or services. on behalf of a particular user (optional)

Top Articles
FedEx | System Down
When Is The Best Time Of Day To Exercise?
Use Copilot in Microsoft Teams meetings
Encore Atlanta Cheer Competition
Cranes For Sale in United States| IronPlanet
Rubratings Tampa
Kansas City Kansas Public Schools Educational Audiology Externship in Kansas City, KS for KCK public Schools
What happened to Lori Petty? What is she doing today? Wiki
Georgia Vehicle Registration Fees Calculator
Nc Maxpreps
What happens if I deposit a bounced check?
Fnv Turbo
Poplar | Genus, Description, Major Species, & Facts
J Prince Steps Over Takeoff
Steve Strange - From Punk To New Romantic
Vocabulario A Level 2 Pp 36 40 Answers Key
Rainfall Map Oklahoma
Boat Jumping Female Otezla Commercial Actress
Qhc Learning
3472542504
8 Ways to Make a Friend Feel Special on Valentine's Day
Wgu Admissions Login
Elizabethtown Mesothelioma Legal Question
272482061
Money blog: Domino's withdraws popular dips; 'we got our dream £30k kitchen for £1,000'
065106619
Strange World Showtimes Near Roxy Stadium 14
Katie Sigmond Hot Pics
Devotion Showtimes Near Regency Buenaventura 6
Suspiciouswetspot
Arrest Gif
Is Poke Healthy? Benefits, Risks, and Tips
Nottingham Forest News Now
Stephanie Bowe Downey Ca
950 Sqft 2 BHK Villa for sale in Devi Redhills Sirinium | Red Hills, Chennai | Property ID - 15334774
J&R Cycle Villa Park
Robot or human?
Mistress Elizabeth Nyc
How To Get Soul Reaper Knife In Critical Legends
Culvers Lyons Flavor Of The Day
Aurora Il Back Pages
Danielle Ranslow Obituary
5A Division 1 Playoff Bracket
3 Zodiac Signs Whose Wishes Come True After The Pisces Moon On September 16
Mathews Vertix Mod Chart
Cch Staffnet
Kaamel Hasaun Wikipedia
Vcuapi
Ff14 Palebloom Kudzu Cloth
Latest Posts
Article information

Author: Fr. Dewey Fisher

Last Updated:

Views: 5988

Rating: 4.1 / 5 (62 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Fr. Dewey Fisher

Birthday: 1993-03-26

Address: 917 Hyun Views, Rogahnmouth, KY 91013-8827

Phone: +5938540192553

Job: Administration Developer

Hobby: Embroidery, Horseback riding, Juggling, Urban exploration, Skiing, Cycling, Handball

Introduction: My name is Fr. Dewey Fisher, I am a powerful, open, faithful, combative, spotless, faithful, fair person who loves writing and wants to share my knowledge and understanding with you.