← All articles

AWS Cognito Token Expiration Time: Defaults and Rotation

Two blank notebooks of different sizes with a loose amber tab between them.
Keep token validity settings and replacement behavior distinct in your records.

Key takeaways

  • Cognito access and ID tokens default to 60 minutes and can be set between 5 minutes and 24 hours, while refresh tokens range from 1 hour to 10 years.
  • Changing token expiration only affects tokens issued after the update; existing tokens, including long-lived refresh tokens, keep their original lifetime until they expire or are revoked.
  • The 2025 Cognito update made refresh tokens rotate on each use, and reuse of a superseded token can invalidate the entire token family, forcing re-authentication.
  • AWS STS AssumeRole sessions default to 1 hour and cap at 12 hours under normal conditions, making them far shorter-lived than Cognito refresh tokens.
  • Vaults store secret values but do not track owners, expiry dates, or rotation deadlines, so long-lived credentials need a separate lifecycle inventory.

The default AWS Cognito token expiration time is 60 minutes for access tokens, 60 minutes for ID tokens, and 30 days for refresh tokens, and you can adjust each between 5 minutes and 24 hours (refresh up to 10 years). This guide covers changing them via the console and TokenValidityUnits API, the 2025 refresh token rotation change, and how these lifetimes compare to AWS STS and Azure AD.

What is the default AWS Cognito token expiration time for access, ID, and refresh tokens?

Cognito's defaults: access tokens and ID tokens expire after 60 minutes, and refresh tokens after 30 days. Access and ID tokens can be set anywhere from 5 minutes to 24 hours; refresh tokens from 1 hour to 10 years. The AWS Cognito developer guide covers these settings and the TokenValidityUnits API that controls whether you configure them in minutes, hours, or days.

The refresh token's long range is where teams get burned. A 10-year refresh token behaves like a long-lived credential, not a session artifact, and nobody files a rotation deadline for something that outlives the team that created it. The same sprawl problem shows up with GitHub PATs and Stripe API keys: the vault stores the value, but nothing tracks who owns it or when it dies.

That gap is the reason KeyGuardRail exists: metadata-only monitoring of expiry and ownership across providers, without holding your secret values.

How do you change the token expiration time in a Cognito user pool?

In the AWS console, open your user pool, go to the App integration tab, and select the app client. There you can set the access token, ID token, and refresh token expiration directly. Access and ID tokens accept 5 minutes to 24 hours; refresh tokens accept 1 hour to 10 years. One constraint trips people up: the refresh token expiration must be at least as long as the access and ID token expirations, or the console rejects the change.

Setting units with TokenValidityUnits

The console only shows hours for access and ID tokens. The API is more flexible. TokenValidityUnits lets you specify the unit for each token type independently: seconds, minutes, hours, or days. You then pair that with AccessTokenValidity, IdTokenValidity, or RefreshTokenValidity in a CreateUserPoolClient or UpdateUserPoolClient call. For example, a 30-minute access token is TokenValidityUnits: {AccessToken: "minutes"} with AccessTokenValidity: 30. If you omit TokenValidityUnits, the values default to hours.

Why existing tokens keep their old lifetime

Changing the expiration only affects tokens issued after the update. Every access, ID, and refresh token already in circulation runs out on its original schedule, so a user with a 10-year refresh token keeps it until it expires or you revoke it. That gap matters for your rotation policy: tightening the setting is not the same as invalidating what developers and integrations already hold. Track which app clients changed, when, and which long-lived tokens are still outstanding until they cycle out, the same way you track any expiring credential (see credential expiration reminder tools for IT teams).

What did the 2025 Amazon Cognito refresh token rotation change alter?

The 2025 Cognito update changed refresh tokens from static, reusable strings into rotating ones. Each refresh grants a new refresh token, and the old one is retired. Clients that cache a refresh token and reuse it after rotation now trigger detection logic instead of silently succeeding, per AWS's Cognito documentation.

Reuse detection and token families

When a retired refresh token is presented, Cognito treats it as a possible theft signal. Tokens derived from the same original grant form a family, and reuse of a superseded token can invalidate the whole family, forcing a fresh login. This mirrors the OAuth 2.0 BCP on refresh token rotation. The practical consequence: a 30/60/90 day rotation policy for refresh tokens is now partly enforced by the token issuer, not just by your runbook.

Impact on mobile and SPA clients

Clients that persist one refresh token forever will break once rotation is on. Mobile apps and SPAs need to overwrite the stored token on every refresh and handle a failed refresh by re-authenticating. If your team tracks which client owns which token and when it expires, that metadata now matters more than the secret value itself; a registry of ownership and expiry deadlines (the approach behind alternatives to manual credential rotation tracking) keeps humans out of the transport layer.

How do Cognito token lifetimes compare to AWS STS token expiration times?

Cognito and STS issue tokens for different jobs, so their knobs sit in different places. STS AssumeRole sessions default to 1 hour, can be raised to 12 hours at the API or role level, and stretch further only when the role's maximum session duration allows it. Cognito user pools issue access, ID, and refresh tokens with validity you set per token type, in minutes, hours, or days via the console or TokenValidityUnits.

Cognito user poolAWS STS AssumeRole
Default lifetime1 hour (access and ID)1 hour
Typical maximumDays (refresh token)12 hours, longer with role conditions
PurposeEnd-user app sessionsMachine and service access to AWS
Who rotatesUser re-authenticates via refresh tokenCaller re-assumes the role

The practical difference between the two systems comes down to who renews the token and how often. STS tokens expire fast and get re-issued by code on every call, so expiry rarely surprises anyone; the worst case is a failed API request and a retry with a fresh session. Cognito refresh tokens can live for days, months, or years, and nothing in the user pool tells you who owns the client, when it last rotated, or whether a 30/60/90 day rotation policy is actually being met. A leaked refresh token with a ten-year lifetime is a standing backdoor that no dashboard in the AWS console will surface for you. That is the gap a credential lifecycle layer covers: it records the owner, the expiry, and the rotation deadline for every long-lived credential, the same way it does for API key expiration policy examples for small teams across Stripe and GitHub.

How do OAuth2 access token expiration rules apply to Cognito-issued tokens?

Cognito is an OAuth2 issuer, so its access tokens follow the spec's conventions rather than any fixed rule. RFC 6749 does not mandate an access token lifetime; it requires only that tokens carry an expiry and that clients use the refresh grant to get new ones. That is why the user pool setting is yours to choose: Cognito's default 60-minute access token expiration time is a configuration default, not a protocol requirement.

The spec also assumes bearer tokens: anyone holding the JWT can use it until it expires, with no revocation check by the resource server. Shorter lifetimes cap that exposure, the same reasoning behind STS session tokens defaulting to one hour under AssumeRole and capping at 12 hours (AWS STS AssumeRole documentation).

Practically, treat the refresh token as your real control surface. Keep access tokens short, set refresh token rotation deliberately, and record each pool's expiry settings alongside the owners and rotation deadlines for the rest of your credentials; a metadata-only inventory such as KeyGuardRail can hold that trail without custody of the secret values (more at credential lifecycle resources).

How do Azure AD access token lifetimes and service principal secret rotation differ from Cognito's model?

Azure AD issues access tokens with a default lifetime of 60-90 minutes, and you can adjust that with configurable token lifetime policies. Cognito takes a different approach: you set fixed expiration values per user pool for access, ID, and refresh tokens, and every token issued from that pool follows them. Azure's model is per-policy and per-principal; Cognito's is per-pool.

Azure service principal secret rotation

Service principals in Azure authenticate with client secrets that can live up to 24 months. After expiry, the secret stops working and any workload using it fails until someone adds a new one and updates the app config. That makes client secrets a long-lived credential problem: you need an owner, a rotation deadline, and an audit trail for each one, or you end up with the same secrets sprawl you have in AWS.

Where Azure API Management API key authentication fits

APIs published through Azure API Management often rely on subscription keys, which are long-lived and tied to a user or product. Like a Cognito refresh token, an API key that expires without a named owner and a rotation policy becomes an outage waiting to happen. Treat both the same way: short-lived creds where you can, tracked expiry metadata where you cannot.

When should short-lived credentials be preferred over long-lived tokens?

Use short-lived credentials for anything a machine does. STS sessions, short Cognito access tokens, and scoped API credentials limit the blast radius of a leaked key to minutes instead of months, and they remove the human from the transport layer, which is where most secrets sprawl starts. For STS, AWS documentation on GetSessionToken maximum durations caps default sessions at one hour and allows up to 12 hours with MFA.

Reserve longer-lived refresh tokens for interactive human sessions, where re-authenticating every 15 minutes is worse than the risk. Whatever long-lived remainder survives, apply a 30/60/90 day rotation policy and record an owner and expiry date for each one. The rule of thumb: if a workload can fetch a fresh credential at runtime, it should never hold one that outlives the deploy.

How do you track token and credential expiry across Cognito, STS, and SaaS providers?

Cognito access and ID tokens expire on their own, so they rarely need a calendar. The credentials around them do not: app client secrets, IAM users backing STS assumptions, Stripe restricted keys, GitHub PATs, and the 30/60/90 day rotation policy you wrote down for everything else. A vault stores the secret value; it does not tell you who owns a key or when it is due.

What a vault does and does not track

HashiCorp Vault, Infisical, and Doppler handle storage, access control, and delivery of values. Lifecycle coordination, meaning an owner named per credential, an expiry date, and a rotation deadline someone is accountable for, usually lives in a spreadsheet or nowhere. Secrets sprawl starts when a dev copies a key into a Postman collection and the vault record loses its owner.

KeyGuardRail monitors credential metadata only: owner, expiry, rotation deadline. You never hand us the secret value. It sits next to your vault, not instead of it.

Running the same criteria against our own product

Same test for everyone: does the tool name an owner per credential, track expiry, and enforce rotation deadlines?

  • Doppler: strong config storage and delivery; lifecycle ownership tracking is not its focus.
  • HashiCorp Vault: deep secrets infrastructure; expiry calendaring across SaaS providers is out of scope.
  • Infisical: solid open-source vault; same gap on cross-provider ownership metadata.
  • KeyGuardRail: metadata-only lifecycle monitoring, self-serve signup. We do not store values, so we cannot rotate anything for you.

FAQ

Can I set a Cognito access token to expire after more than 24 hours?

No. Access and ID tokens cap at 24 hours, with a floor of 5 minutes. If you need sessions that outlast that, the design is a short access token paired with a longer refresh token, which can run from 1 hour up to 10 years. The client then uses the refresh grant to mint new access tokens as needed.

Does changing the token expiration time in Cognito invalidate tokens that are already issued?

No. New expiration values apply only to tokens issued after the update. Anything already in circulation, including a 10-year refresh token, runs out on its original schedule unless you revoke it. Track which app clients changed and which long-lived tokens remain outstanding until they cycle out naturally, the same way you track any expiring credential.

What happens if a rotated refresh token is reused in Cognito?

Cognito treats reuse of a superseded token as a possible theft signal. Tokens derived from the same original grant form a family, and reuse can invalidate the entire family, forcing users to re-authenticate. This mirrors the OAuth 2.0 best practice on refresh token rotation and makes rotation partly enforced by the token issuer rather than only your runbook.

How long do AWS STS session tokens last by default?

One hour for AssumeRole sessions by default. That can be raised to 12 hours at the API or role level, and further only when the role's maximum session duration allows it. GetSessionToken sessions also default to one hour and can extend up to 12 hours when MFA is used, per AWS documentation.

Do Cognito refresh tokens expire if the user is inactive?

No. Cognito refresh tokens carry a fixed expiration from 1 hour to 10 years and do not expire through inactivity. A user who disappears for months can return and refresh within the token's lifetime. If you need inactivity-based session expiry, enforce it in your application rather than relying on the user pool setting.