Class RefreshTokenService<TRequest, TResponse>
implement this class to define your own refresh token endpoints.
Inherited Members
Namespace: FastEndpoints.Security
Assembly: FastEndpoints.Security.dll
Syntax
public abstract class RefreshTokenService<TRequest, TResponse> : Endpoint<TRequest, TResponse>, IEndpoint, IEventBus, IServiceResolverBase where TRequest : notnull, TokenRequest, new() where TResponse : notnull, TokenResponse, new()
Type Parameters
Name | Description |
---|---|
TRequest | the type of the request dto that will be accepted by the refresh endpoint |
TResponse | the type of the response dto that will be sent by the refresh endpoint |
Methods
CreateCustomToken<T>(string, Action<UserPrivileges>, Func<TResponse, T>)
create a token response and map it to a different type. useful if you need to create the token manually by yourself.
Declaration
public Task<T> CreateCustomToken<T>(string userId, Action<UserPrivileges> privileges, Func<TResponse, T> map)
Parameters
Type | Name | Description |
---|---|---|
string | userId | the id of the user to create the token for |
Action<UserPrivileges> | privileges | the user priviledges to be embeded in the jwt such as roles/claims/permissions |
Func<TResponse, T> | map | a func that maps properties from |
Returns
Type | Description |
---|---|
Task<T> |
Type Parameters
Name | Description |
---|---|
T | the type to map to |
PersistTokenAsync(TResponse)
this method will be called whenever a new access/refresh token pair is being generated. store the tokens and expiry dates however you wish for the purpose of verifying future refresh requests.
Declaration
public abstract Task PersistTokenAsync(TResponse response)
Parameters
Type | Name | Description |
---|---|---|
TResponse | response | the response dto containing the tokens that's about to be sent to the requesting client |
Returns
Type | Description |
---|---|
Task |
RefreshRequestValidationAsync(TRequest)
validate the incoming refresh request by checking the token and expiry against the previously stored data.
if the token is not valid and a new token pair should not be created, simply add validation errors using the AddError()
method.
the failures you add will be sent to the requesting client.
if no failures are added, validation passes and a new token pair will be created and sent to the client.
Declaration
public abstract Task RefreshRequestValidationAsync(TRequest req)
Parameters
Type | Name | Description |
---|---|---|
TRequest | req | the incoming refresh request dto |
Returns
Type | Description |
---|---|
Task |
SetRenewalPrivilegesAsync(TRequest, UserPrivileges)
specify the user privileges to be embeded in the jwt when a refresh request is received and validation has passed. this only applies to renewal/refresh requests received to the refresh endpoint and not the initial jwt creation.
Declaration
public abstract Task SetRenewalPrivilegesAsync(TRequest request, UserPrivileges privileges)
Parameters
Type | Name | Description |
---|---|---|
TRequest | request | the request dto received from the client |
UserPrivileges | privileges | the user priviledges to be embeded in the jwt such as roles/claims/permissions |
Returns
Type | Description |
---|---|
Task |
Setup(Action<RefreshServiceOptions>)
configure the refresh token service options
Declaration
public void Setup(Action<RefreshServiceOptions> options)
Parameters
Type | Name | Description |
---|---|---|
Action<RefreshServiceOptions> | options | action to be performed on the refresh service options object |