How to add configuration to auto save access token and refresh token in AspnetUserToken table

Lavanya Chakkaravel 20 Reputation points
2025-04-29T10:35:22.7966667+00:00

Hi,

I am using Microsoft.EntityFrameworkCore (Version 8.0.6) + Microsoft.AspNetCore.Identity.EntityFrameworkCore(Version 8.0.6) + Npgsql.EntityFrameworkCore.PostgreSQL (Version 8).

I want to save the auto generated token from Identity Authentication into AspNetUsersToken Table. Is that possible to save the token without any customized method? I want to add configuration in program.cs to automatically save the token into table without any manual changes.

Is Identity AspNetCore 8 will have configuration to auto save token in table?

Note: I am not using JWT, not any third party authentication.

ASP.NET Core Training
ASP.NET Core Training
ASP.NET Core: A set of technologies in the .NET Framework for building web applications and XML web services.Training: Instruction to develop new skills.
81 questions
0 comments No comments
{count} votes

Accepted answer
  1. Pradeep M 9,685 Reputation points Microsoft External Staff Volunteer Moderator
    2025-04-29T11:09:12.8766667+00:00

    Hi Lavanya Chakkaravel

    Thank you for reaching out to Microsoft Q & A forum. 

    In ASP.NET Core Identity (including version 8), there is currently no built-in configuration option to automatically save access or refresh tokens to the AspNetUserTokens table without writing custom logic. The default behavior only supports storing tokens from external authentication providers. 

    Since you're not using JWT or any third-party authentication, you will need to manually save tokens using the UserManager service. For example: 

    await userManager.SetAuthenticationTokenAsync(user, "MyApp", "AccessToken", token);
    
    

    At this time, configuring token storage solely through Program.cs is not supported. So, a small amount of custom implementation is necessary to store these tokens as part of your authentication flow.    

    If you have found the answer provided to be helpful, please click on the "Accept answer/Upvote" button so that it is useful for other members in the Microsoft Q&A community.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.