# Refresh tokens in an ASP.NET 9 Blazor web app

**URL:** <https://community.auth0.com/t/refresh-tokens-in-an-asp-net-9-blazor-web-app/187973>\
**Category:** Get Help\
**Tags:** reusable-refresh-tokens, sessions\
**Created:** [June 15, 2025, 1:34pm UTC](https://community.auth0.com/t/refresh-tokens-in-an-asp-net-9-blazor-web-app/187973 "2025-06-15T13:34:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dag.baardsen](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dag.baardsen/32/72721_2.png) [@dag.baardsen](https://community.auth0.com/u/dag.baardsen)\
**Post date:** [June 15, 2025, 1:34pm UTC](https://community.auth0.com/t/refresh-tokens-in-an-asp-net-9-blazor-web-app/187973/1 "2025-06-15T13:34:29Z")

</div>

I have managed to get an access token in my web app, and I guess I am able to retrieve a refresh token, too, but how do I store the refresh token securely, and how do I use it when my access token expires? I am on [ASP.NET](http://ASP.NET) 9, using this wiring:

* * *

```csharp
builder.Services.AddAuth0WebAppAuthentication(options =>
{
    options.Domain = builder.Configuration["Auth0:Domain"]!;
    options.ClientId = builder.Configuration["Auth0:ClientId"]!;
    options.ClientSecret = builder.Configuration["Auth0:ClientSecret"];
    options.Scope = "openid profile email offline_access";
})
.WithAccessToken(options =>
{
    options.Audience = builder.Configuration["Auth0:Api:Audience"];
    options.UseRefreshTokens = true;
});

builder.Services.ConfigureApplicationCookie(options =>
{
    options.ExpireTimeSpan = TimeSpan.FromDays(30);
    options.SlidingExpiration = true;
    options.Cookie.IsEssential = true;
    options.Cookie.HttpOnly = true;
    options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
    options.Cookie.SameSite = SameSiteMode.Lax;
});

```

---

<div class="post-metadata">

**Author:** ![lafayette.duarte](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lafayette.duarte/32/60012_2.png) [@lafayette.duarte](https://community.auth0.com/u/lafayette.duarte)\
**Post date:** [June 16, 2025, 12:30pm UTC](https://community.auth0.com/t/refresh-tokens-in-an-asp-net-9-blazor-web-app/187973/2 "2025-06-16T12:30:24Z")

</div>

Hi there.  
here, depends on how your blazor app is built.  
Duende Software ( the ppl who created and maintains IdentityServer) have a OSS Clibrary that helps with this scenario and others and its quite handy.

Now, the depends part:  
if you are using Blazor server, this doc would help you:

" Since the tokens cannot be managed in the authentication session, you need to store them somewhere else. The options include an in-memory data structure, a distributed cache like redis, or a database. Duende.AccessTokenManagement describes this store for tokens with the _IUserTokenStore_ interface. In non-blazor scenarios, the default implementation that stores the tokens in the session is used. In your Blazor server application, you’ll need to decide where you want to store the tokens and implement the store interface."  
[Blazor Server Access Token Management | Duende Software Docs](https://docs.duendesoftware.com/accesstokenmanagement/blazor-server/#token-storage)

If you are using blazor as a SPA, it should be a public client.  
this may point you to the right direction on this scenario ( event tho is a MsEntra article, the principle stands):  
[Secure an ASP.NET Core Blazor Web App with Microsoft Entra ID | Microsoft Learn](https://learn.microsoft.com/en-us/aspnet/core/blazor/security/blazor-web-app-with-entra?view=aspnetcore-9.0&pivots=non-bff-pattern)

Be careful and when using public clients ( there is a whole thing on the security side of things).  
More on the IETF Website:  
[OAuth 2.0 for Browser-Based Applications](https://www.ietf.org/archive/id/draft-ietf-oauth-browser-based-apps-24.html#name-introduction)

And here for an auth0 article on BFF :  
[Backend For Frontend Authentication Pattern with Auth0 and ASP.NET Core](https://auth0.com/blog/backend-for-frontend-pattern-with-auth0-and-dotnet/)

---

<div class="post-metadata">

**Author:** ![dag.baardsen](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dag.baardsen/32/72721_2.png) [@dag.baardsen](https://community.auth0.com/u/dag.baardsen)\
**Post date:** [June 22, 2025, 7:19pm UTC](https://community.auth0.com/t/refresh-tokens-in-an-asp-net-9-blazor-web-app/187973/3 "2025-06-22T19:19:05Z")

</div>

Thanks a lot for pointing me in the right direction!

DagH

---

<div class="post-metadata">

**Author:** ![dag.baardsen](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dag.baardsen/32/72721_2.png) [@dag.baardsen](https://community.auth0.com/u/dag.baardsen)\
**Post date:** [July 3, 2025, 3:20pm UTC](https://community.auth0.com/t/refresh-tokens-in-an-asp-net-9-blazor-web-app/187973/4 "2025-07-03T15:20:09Z")

</div>

For others implementing [ASP.NET](http://ASP.NET) 9 authentication, I ended up with a working Duende Access Token Management based IUserTokenStore, using Refit as my API backend client. However, to get working refresh tokens, I had to implement my own HttpClient to call the /oauth/token endpoint for OIDC to fetch updated access token after expriy.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [July 17, 2025, 3:20pm UTC](https://community.auth0.com/t/refresh-tokens-in-an-asp-net-9-blazor-web-app/187973/5 "2025-07-17T15:20:16Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
