Menu

JWT access + refresh tokens in ASP.NET Core (.NET 10): rotation, revocation and the bugs to avoid
📰

JWT access + refresh tokens in ASP.NET Core (.NET 10): rotation, revocation and the bugs to avoid

DEV Community: aspnet·Pankaj Singh·8 days ago
#5PdVheTJ
#devtoaspnet#devto#dev#refresh#token
Long article (1861 words) — no AI summary yet.
Reading 0:00
15s threshold

I've spent about four and a half years building ASP.NET Core APIs, and JWT auth is still the place I see the most "it works in Postman" security holes. Short-lived access tokens are easy. Refresh tokens that survive a phone reboot and a stolen laptop are harder.

This is the pattern I ship: a short JWT access token, an opaque refresh token stored as a SHA-256 hash, rotation on every refresh, and family-wide revocation when a rotated token shows up again. The code below comes from a .NET 10 / EF Core starter I maintain. It also runs on .NET 8 with almost no changes.

What each token is for

Token Lifetime I use Form Stored how

Access 15 minutes Signed JWT Nowhere (stateless)

Refresh 7 days Opaque random bytes SHA-256 hash in SQL

The access token is what every [Authorize] endpoint checks. The refresh token is only sent to /api/auth/refresh (and revoke).…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.