-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Feature requirements
I'm like: a package user
I want to: refresh tokens without using a database
I that way: I don't need to have the database (and probably pay for it)
Technical solution
This feature will work by the following description:
- Someone send a login request. The request's body:
{
"login": "Admin",
"password": "Admin",
"clientFingerPrint": "{{FINGERPRINT}}"
}The response:
{
"accessToken": {
"value": "{{ACCESS_TOKEN_VALUE}}",
"expiresInUtc": "2021-01-01T00:00:00.0000000Z"
},
"refreshToken": {
"value": "{{REFRESH_TOKEN_VALUE}}",
"expiresInUtc": "2021-01-01T00:00:00.0000000Z"
}
}- After login a user starts to send requests with an access token (as in the usual authentication flow with JWT)
- If the access token has expired, then we send a refresh request. The request's body:
{
"refreshTokenValue": "{{REFRESH_TOKEN}}",
"clientFingerPrint": "{{FINGERPRINT}}"
}The response:
{
"accessToken": {
"value": "{{ACCESS_TOKEN_VALUE}}",
"expiresInUtc": "2021-01-01T00:00:00.0000000Z"
}
}Pay attention - it this feature we have a long-lifetime refresh token, so we don't need to send new refresh token in the response
- If the refresh token has expired we send an unauthorized error
Feature contract
For configuring login, refresh and different options we can use the following contract:
public IServiceCollection AddLoginWithRefresh(this IServiceCollection services, RefreshTokenOptions refreshTokenOptions = null)And the .NET6 example will look like this:
using TourmalineCore.AspNetCore.JwtAuthentication.Core;
var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration;
var authenticationOptions = _configuration.GetSection(nameof(AuthenticationOptions)).Get<AuthenticationOptions>();
var refreshTokenOptions = _configuration.GetSection(nameof(RefreshTokenOptions)).Get<RefreshTokenOptions>();
buidler.
services
.AddJwtAuthentication(authenticationOptions)
.AddLoginWithRefresh(refreshTokenOptions);
var app = builder.Build();
app
.UseJwtAuthentication()
.UseDefaultLoginMiddleware()
.UseRefreshTokenMiddleware();Additional requirements
- implement the refresh tests (use examples in .net5, .net6)
- add an example for using refresh without database (for .netcore3.0, netcore3.1, .net5, .net6)
- add the documentation section to the
Coreproject
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request