Refresh Tokens — IdentityServer4 1.0.0 documentation (2024)

Since access tokens have finite lifetimes, refresh tokens allow requesting new access tokens without user interaction.

Refresh tokens are supported for the following flows: authorization code, hybrid and resource owner password credential flow.The clients needs to be explicitly authorized to request refresh tokens by setting AllowOfflineAccess to true.

Additional client settings

AbsoluteRefreshTokenLifetime
Maximum lifetime of a refresh token in seconds. Defaults to 2592000 seconds / 30 days. Zero allows refresh tokens that, when used with RefreshTokenExpiration = Sliding only expire after the SlidingRefreshTokenLifetime is passed.
SlidingRefreshTokenLifetime
Sliding lifetime of a refresh token in seconds. Defaults to 1296000 seconds / 15 days
RefreshTokenUsage

ReUse the refresh token handle will stay the same when refreshing tokens

OneTimeOnly the refresh token handle will be updated when refreshing tokens

RefreshTokenExpiration

Absolute the refresh token will expire on a fixed point in time (specified by the AbsoluteRefreshTokenLifetime). This is the default.

Sliding when refreshing the token, the lifetime of the refresh token will be renewed (by the amount specified in SlidingRefreshTokenLifetime). The lifetime will not exceed AbsoluteRefreshTokenLifetime.

UpdateAccessTokenClaimsOnRefresh
Gets or sets a value indicating whether the access token (and its claims) should be updated on a refresh token request.

Note

Public clients (clients without a client secret) should rotate their refresh tokens. Set the RefreshTokenUsage to OneTimeOnly.

Requesting a refresh token

You can request a refresh token by adding a scope called offline_access to the scope parameter.

Requesting an access token using a refresh token

To get a new access token, you send the refresh token to the token endpoint.This will result in a new token response containing a new access token and its expiration and potentially also a new refresh token depending on the client configuration (see above).

POST /connect/token client_id=client& client_secret=secret& grant_type=refresh_token& refresh_token=hdh922

(Form-encoding removed and line breaks added for readability)

Note

You can use the IdentityModel client library to programmatically access the token endpoint from .NET code. For more information check the IdentityModel docs.

Note

The refresh token, must be valid or an invalid_grant error is returned. By default, a refresh_token can only be used once. Using an already used refresh_token will result in an invalid_grant error.

Customizing refresh token behavior

All refresh token handling is implemented in the DefaultRefreshTokenService (which is the default implementation of the IRefreshTokenService interface):

public interface IRefreshTokenService{ /// <summary> /// Validates a refresh token. /// </summary> Task<TokenValidationResult> ValidateRefreshTokenAsync(string token, Client client); /// <summary> /// Creates the refresh token. /// </summary> Task<string> CreateRefreshTokenAsync(ClaimsPrincipal subject, Token accessToken, Client client); /// <summary> /// Updates the refresh token. /// </summary> Task<string> UpdateRefreshTokenAsync(string handle, RefreshToken refreshToken, Client client);}

The logic around refresh token handling is pretty involved, and we don’t recommend implementing the interface from scratch,unless you exactly know what you are doing.If you want to customize certain behavior, it is more recommended to derive from the default implementation and call the base checks first.

The most common customization that you probably want to do is how to deal with refresh token replays.This is for situations where the token usage has been set to one-time only, but the same token gets sent more than once.This could either point to a replay attack of the refresh token, or to faulty client code like logic bugs or race conditions.

It is important to note, that a refresh token is never deleted in the database.Once it has been used, the ConsumedTime property will be set.If a token is received that has already been consumed, the default service will call a virtual method called AcceptConsumedTokenAsync.

The default implementation will reject the request, but here you can implement custom logic like grace periods,or revoking additional refresh or access tokens.

Refresh Tokens — IdentityServer4 1.0.0 documentation (2024)
Top Articles
How to Invest £1,000: Where to Invest 1,000 and Double It | Moneyfarm
Buying Car Insurance Online: How To Do It (2024 Tips)
Victor Spizzirri Linkedin
Dricxzyoki
The Best Classes in WoW War Within - Best Class in 11.0.2 | Dving Guides
Danielle Longet
What’s the Difference Between Cash Flow and Profit?
Little Rock Arkansas Craigslist
zopiclon | Apotheek.nl
Dutchess Cleaners Boardman Ohio
Overton Funeral Home Waterloo Iowa
Viprow Golf
9044906381
Dr Adj Redist Cadv Prin Amex Charge
Equipamentos Hospitalares Diversos (Lote 98)
Alexander Funeral Home Gallatin Obituaries
Star Wars: Héros de la Galaxie - le guide des meilleurs personnages en 2024 - Le Blog Allo Paradise
Parent Resources - Padua Franciscan High School
Praew Phat
Spider-Man: Across The Spider-Verse Showtimes Near Marcus Bay Park Cinema
Apply for a credit card
Nearest Walgreens Or Cvs Near Me
Ein Blutbad wie kein anderes: Evil Dead Rise ist der Horrorfilm des Jahres
Barber Gym Quantico Hours
Maxpreps Field Hockey
Lexus Credit Card Login
Ficoforum
Select Truck Greensboro
Shia Prayer Times Houston
897 W Valley Blvd
Nurofen 400mg Tabletten (24 stuks) | De Online Drogist
Craigslist/Phx
100 Million Naira In Dollars
Selfservice Bright Lending
Solemn Behavior Antonym
Imperialism Flocabulary Quiz Answers
Ise-Vm-K9 Eol
Frommer's Philadelphia &amp; the Amish Country (2007) (Frommer's Complete) - PDF Free Download
Callie Gullickson Eye Patches
Beaufort SC Mugshots
Carteret County Busted Paper
Tableaux, mobilier et objets d'art
Ehome America Coupon Code
Whitney Wisconsin 2022
DL381 Delta Air Lines Estado de vuelo Hoy y Historial 2024 | Trip.com
Headlining Hip Hopper Crossword Clue
17 of the best things to do in Bozeman, Montana
Doelpuntenteller Robert Mühren eindigt op 38: "Afsluiten in stijl toch?"
Slug Menace Rs3
Diesel Technician/Mechanic III - Entry Level - transportation - job employment - craigslist
Wayward Carbuncle Location
Latest Posts
Article information

Author: Duane Harber

Last Updated:

Views: 5382

Rating: 4 / 5 (71 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Duane Harber

Birthday: 1999-10-17

Address: Apt. 404 9899 Magnolia Roads, Port Royceville, ID 78186

Phone: +186911129794335

Job: Human Hospitality Planner

Hobby: Listening to music, Orienteering, Knapping, Dance, Mountain biking, Fishing, Pottery

Introduction: My name is Duane Harber, I am a modern, clever, handsome, fair, agreeable, inexpensive, beautiful person who loves writing and wants to share my knowledge and understanding with you.