Package for manage refresh token
License
—
Deps
1
Install Size
—
Vulns
✓ 0
Published
Nov 13, 2025
$ dotnet add package EasyRefreshToken|
|
Documentation
Make your TUser inherit from IUser.
Create your own class MyRefreshToken and add to it the properties you want and make it inherit from RefreshToken<TUser, TKey>
If you do not want to add new features, you can skip the previous step.
In AppDbContext Class:
public DbSet<RefreshToken<TUser, TKey>> RefreshTokens { get; set; }
or public DbSet<MyRefreshToken> RefreshTokens { get; set; }
In Program Class:
builder.Services.AddRefreshToken<AppDbContext, RefreshToken<TUser, TKey>, TUser, TKey>();
or builder.Services.AddRefreshToken<AppDbContext, MyRefreshToken, TUser, TKey>();
Don't forget:
Add-Migration
Update-Database
Now you can use ITokenService<TKey> that contains:
OnLoginAsyncOnLogoutAsyncOnAccessTokenExpiredAsyncOnChangePasswordAsyncClearAsyncClearExpiredAsyncAnd you can control with many options:
MaxNumberOfActiveDevicesTokenExpiredDaysPreventingLoginWhenAccessToMaxNumberOfActiveDevicesTokenGenerationMethodOnChangePasswordBehaviorSaveChangesYou can specifies a life time of the Service (the default is Scoped).
For MaxNumberOfActiveDevices use MaxNumberOfActiveDevices.Config().
Note: when change on options, I highly recommend cleaning the table by Clear
Enjoy ...