Search Results for

    Show / Hide Table of Contents

    Class RefreshTokenService<TRequest, TResponse>

    implement this class to define your own refresh token endpoints.

    Inheritance
    object
    BaseEndpoint
    Endpoint<TRequest, TResponse>
    RefreshTokenService<TRequest, TResponse>
    Implements
    IEndpoint
    IEventBus
    IServiceResolverBase
    Inherited Members
    Endpoint<TRequest, TResponse>.HandleAsync(TRequest, CancellationToken)
    Endpoint<TRequest, TResponse>.ExecuteAsync(TRequest, CancellationToken)
    Endpoint<TRequest, TResponse>.TryResolve<TService>()
    Endpoint<TRequest, TResponse>.TryResolve(Type)
    Endpoint<TRequest, TResponse>.Resolve<TService>()
    Endpoint<TRequest, TResponse>.Resolve(Type)
    Endpoint<TRequest, TResponse>.CreateScope()
    Endpoint<TRequest, TResponse>.TryResolve<TService>(string)
    Endpoint<TRequest, TResponse>.TryResolve(Type, string)
    Endpoint<TRequest, TResponse>.Resolve<TService>(string)
    Endpoint<TRequest, TResponse>.Resolve(Type, string)
    Endpoint<TRequest, TResponse>.Route<T>(string, bool)
    Endpoint<TRequest, TResponse>.Query<T>(string, bool)
    Endpoint<TRequest, TResponse>.FormFileSectionsAsync(CancellationToken)
    Endpoint<TRequest, TResponse>.FormMultipartSectionsAsync(CancellationToken)
    Endpoint<TRequest, TResponse>.PublishAsync<TEvent>(TEvent, Mode, CancellationToken)
    Endpoint<TRequest, TResponse>.CreateTokenWith<TService>(string, Action<UserPrivileges>, TRequest)
    Endpoint<TRequest, TResponse>.ProcessorState<TState>()
    Endpoint<TRequest, TResponse>.OnBeforeValidate(TRequest)
    Endpoint<TRequest, TResponse>.OnBeforeValidateAsync(TRequest, CancellationToken)
    Endpoint<TRequest, TResponse>.OnAfterValidate(TRequest)
    Endpoint<TRequest, TResponse>.OnAfterValidateAsync(TRequest, CancellationToken)
    Endpoint<TRequest, TResponse>.OnBeforeHandle(TRequest)
    Endpoint<TRequest, TResponse>.OnBeforeHandleAsync(TRequest, CancellationToken)
    Endpoint<TRequest, TResponse>.OnAfterHandle(TRequest, TResponse)
    Endpoint<TRequest, TResponse>.OnAfterHandleAsync(TRequest, TResponse, CancellationToken)
    Endpoint<TRequest, TResponse>.OnValidationFailed()
    Endpoint<TRequest, TResponse>.OnValidationFailedAsync(CancellationToken)
    Endpoint<TRequest, TResponse>.User
    Endpoint<TRequest, TResponse>.Response
    Endpoint<TRequest, TResponse>.Config
    Endpoint<TRequest, TResponse>.Env
    Endpoint<TRequest, TResponse>.Logger
    Endpoint<TRequest, TResponse>.BaseURL
    Endpoint<TRequest, TResponse>.HttpMethod
    Endpoint<TRequest, TResponse>.Form
    Endpoint<TRequest, TResponse>.Files
    Endpoint<TRequest, TResponse>.ResponseStarted
    Endpoint<TRequest, TResponse>.SendAsync(TResponse, int, CancellationToken)
    Endpoint<TRequest, TResponse>.SendResultAsync(IResult)
    Endpoint<TRequest, TResponse>.SendInterceptedAsync(object, int, CancellationToken)
    Endpoint<TRequest, TResponse>.SendCreatedAtAsync<TEndpoint>(object, TResponse, Http?, int?, bool, CancellationToken)
    Endpoint<TRequest, TResponse>.SendCreatedAtAsync(string, object, TResponse, bool, CancellationToken)
    Endpoint<TRequest, TResponse>.SendAcceptedAtAsync<TEndpoint>(object, TResponse, Http?, int?, bool, CancellationToken)
    Endpoint<TRequest, TResponse>.SendAcceptedAtAsync(string, object, TResponse, bool, CancellationToken)
    Endpoint<TRequest, TResponse>.SendStringAsync(string, int, string, CancellationToken)
    Endpoint<TRequest, TResponse>.SendOkAsync(TResponse, CancellationToken)
    Endpoint<TRequest, TResponse>.SendOkAsync(CancellationToken)
    Endpoint<TRequest, TResponse>.SendErrorsAsync(int, CancellationToken)
    Endpoint<TRequest, TResponse>.SendNoContentAsync(CancellationToken)
    Endpoint<TRequest, TResponse>.SendNotFoundAsync(CancellationToken)
    Endpoint<TRequest, TResponse>.SendUnauthorizedAsync(CancellationToken)
    Endpoint<TRequest, TResponse>.SendForbiddenAsync(CancellationToken)
    Endpoint<TRequest, TResponse>.SendRedirectAsync(string, bool, bool)
    Endpoint<TRequest, TResponse>.SendHeadersAsync(Action<IHeaderDictionary>, int, CancellationToken)
    Endpoint<TRequest, TResponse>.SendBytesAsync(byte[], string, string, DateTimeOffset?, bool, CancellationToken)
    Endpoint<TRequest, TResponse>.SendFileAsync(FileInfo, string, DateTimeOffset?, bool, CancellationToken)
    Endpoint<TRequest, TResponse>.SendStreamAsync(Stream, string, long?, string, DateTimeOffset?, bool, CancellationToken)
    Endpoint<TRequest, TResponse>.SendEventStreamAsync<T>(string, IAsyncEnumerable<T>, CancellationToken)
    Endpoint<TRequest, TResponse>.SendEmptyJsonObject(CancellationToken)
    Endpoint<TRequest, TResponse>.AccessControl(string, Apply?, params string[])
    Endpoint<TRequest, TResponse>.AccessControl(string, params string[])
    Endpoint<TRequest, TResponse>.AllowAnonymous(params Http[])
    Endpoint<TRequest, TResponse>.AllowAnonymous(string[])
    Endpoint<TRequest, TResponse>.AllowFileUploads(bool)
    Endpoint<TRequest, TResponse>.AllowFormData(bool)
    Endpoint<TRequest, TResponse>.AuthSchemes(params string[])
    Endpoint<TRequest, TResponse>.Claims(params string[])
    Endpoint<TRequest, TResponse>.ClaimsAll(params string[])
    Endpoint<TRequest, TResponse>.Connect(params string[])
    Endpoint<TRequest, TResponse>.Connect(string, Expression<Func<TRequest, object>>)
    Endpoint<TRequest, TResponse>.Delete(params string[])
    Endpoint<TRequest, TResponse>.Delete(string, Expression<Func<TRequest, object>>)
    Endpoint<TRequest, TResponse>.Description(Action<RouteHandlerBuilder>, bool)
    Endpoint<TRequest, TResponse>.DontAutoSendResponse()
    Endpoint<TRequest, TResponse>.DontAutoTag()
    Endpoint<TRequest, TResponse>.DontCatchExceptions()
    Endpoint<TRequest, TResponse>.DontThrowIfValidationFails()
    Endpoint<TRequest, TResponse>.EnableAntiforgery()
    Endpoint<TRequest, TResponse>.Get(params string[])
    Endpoint<TRequest, TResponse>.Get(string, Expression<Func<TRequest, object>>)
    Endpoint<TRequest, TResponse>.Group<TEndpointGroup>()
    Endpoint<TRequest, TResponse>.Head(params string[])
    Endpoint<TRequest, TResponse>.Head(string, Expression<Func<TRequest, object>>)
    Endpoint<TRequest, TResponse>.Idempotency(Action<IdempotencyOptions>)
    Endpoint<TRequest, TResponse>.Options(Action<RouteHandlerBuilder>)
    Endpoint<TRequest, TResponse>.Options(params string[])
    Endpoint<TRequest, TResponse>.Options(string, Expression<Func<TRequest, object>>)
    Endpoint<TRequest, TResponse>.Patch(params string[])
    Endpoint<TRequest, TResponse>.Patch(string, Expression<Func<TRequest, object>>)
    Endpoint<TRequest, TResponse>.Permissions(params string[])
    Endpoint<TRequest, TResponse>.PermissionsAll(params string[])
    Endpoint<TRequest, TResponse>.Policy(Action<AuthorizationPolicyBuilder>)
    Endpoint<TRequest, TResponse>.Policies(params string[])
    Endpoint<TRequest, TResponse>.Post(params string[])
    Endpoint<TRequest, TResponse>.Post(string, Expression<Func<TRequest, object>>)
    Endpoint<TRequest, TResponse>.PostProcessor<TPostProcessor>()
    Endpoint<TRequest, TResponse>.PostProcessors(params IPostProcessor<TRequest, TResponse>[])
    Endpoint<TRequest, TResponse>.PreProcessor<TPreProcessor>()
    Endpoint<TRequest, TResponse>.PreProcessors(params IPreProcessor<TRequest>[])
    Endpoint<TRequest, TResponse>.Put(params string[])
    Endpoint<TRequest, TResponse>.Put(string, Expression<Func<TRequest, object>>)
    Endpoint<TRequest, TResponse>.RequestBinder(IRequestBinder<TRequest>)
    Endpoint<TRequest, TResponse>.ResponseCache(int, ResponseCacheLocation, bool, string, string[])
    Endpoint<TRequest, TResponse>.ResponseInterceptor(IResponseInterceptor)
    Endpoint<TRequest, TResponse>.Roles(params string[])
    Endpoint<TRequest, TResponse>.RoutePrefixOverride(string)
    Endpoint<TRequest, TResponse>.Routes(params string[])
    Endpoint<TRequest, TResponse>.SerializerContext<TContext>(TContext)
    Endpoint<TRequest, TResponse>.SerializerContext<TContext>()
    Endpoint<TRequest, TResponse>.Summary(Action<EndpointSummary>)
    Endpoint<TRequest, TResponse>.Summary(Action<EndpointSummary<TRequest>>)
    Endpoint<TRequest, TResponse>.Summary(EndpointSummary)
    Endpoint<TRequest, TResponse>.Tags(params string[])
    Endpoint<TRequest, TResponse>.Throttle(int, double, string)
    Endpoint<TRequest, TResponse>.Trace(params string[])
    Endpoint<TRequest, TResponse>.Trace(string, Expression<Func<TRequest, object>>)
    Endpoint<TRequest, TResponse>.Validator<TValidator>()
    Endpoint<TRequest, TResponse>.Verbs(params Http[])
    Endpoint<TRequest, TResponse>.Verbs(params string[])
    Endpoint<TRequest, TResponse>.Version(int, int)
    Endpoint<TRequest, TResponse>.ValidationFailed
    Endpoint<TRequest, TResponse>.AddError(ValidationFailure)
    Endpoint<TRequest, TResponse>.AddError(string, string, Severity)
    Endpoint<TRequest, TResponse>.AddError(Expression<Func<TRequest, object>>, string, string, Severity)
    Endpoint<TRequest, TResponse>.ThrowError(ValidationFailure, int?)
    Endpoint<TRequest, TResponse>.ThrowError(string, int?)
    Endpoint<TRequest, TResponse>.ThrowError(string, string, Severity, int?)
    Endpoint<TRequest, TResponse>.ThrowError(Expression<Func<TRequest, object>>, string, int?)
    Endpoint<TRequest, TResponse>.ThrowError(Expression<Func<TRequest, object>>, string, string, Severity, int?)
    Endpoint<TRequest, TResponse>.ThrowIfAnyErrors(int?)
    BaseEndpoint.Definition
    BaseEndpoint.HttpContext
    BaseEndpoint.ValidationFailures
    BaseEndpoint.Configure()
    BaseEndpoint.Verbs(params string[])
    BaseEndpoint.Routes(params string[])
    BaseEndpoint.Group<TEndpointGroup>()
    BaseEndpoint.GetAclHash(string)
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: FastEndpoints.Security
    Assembly: FastEndpoints.Security.dll
    Syntax
    public abstract class RefreshTokenService<TRequest, TResponse> : Endpoint<TRequest, TResponse>, IEndpoint, IEventBus, IServiceResolverBase where TRequest : TokenRequest, new() where TResponse : 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>, bool, object?)

    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, bool isRenewal = false, object? request = null)
    Parameters
    Type Name Description
    string userId

    the id of the user to create the token for

    Action<UserPrivileges> privileges

    the user privileges to be embedded in the jwt such as roles/claims/permissions

    Func<TResponse, T> map

    a func that maps properties from TResponse to T

    bool isRenewal

    specify if this is an initial login request or a renewal/refresh request

    object request

    the request dto

    Returns
    Type Description
    Task<T>
    Type Parameters
    Name Description
    T

    the type to map to

    OnAfterInitialTokenCreationAsync(object?, TResponse)

    a hook for modifying the created token response when a login request comes in.

    Declaration
    public virtual Task OnAfterInitialTokenCreationAsync(object? request, TResponse response)
    Parameters
    Type Name Description
    object request

    the request dto. maybe null unless you supply it to the CreateTokenWith<TService>(string, Action<UserPrivileges>, TRequest?) method.

    TResponse response

    the token response dto that is created

    Returns
    Type Description
    Task

    OnAfterRenewalTokenCreationAsync(TRequest?, TResponse)

    a hook for modifying the created token response when a renewal request comes in.

    Declaration
    public virtual Task OnAfterRenewalTokenCreationAsync(TRequest? request, TResponse response)
    Parameters
    Type Name Description
    TRequest request

    the request dto. maybe null unless you supply it to the CreateTokenWith<TService>(string, Action<UserPrivileges>, TRequest?) method.

    TResponse response

    the token response dto that is created

    Returns
    Type Description
    Task

    OnBeforeInitialTokenCreationAsync(JwtCreationOptions, object?)

    a hook for modifying jwt creation options per request when a login request comes in. this method is called right before the actual jwt token is created allowing you to override token creation parameters per request if needed.

    Declaration
    public virtual Task OnBeforeInitialTokenCreationAsync(JwtCreationOptions jwtOptions, object? request)
    Parameters
    Type Name Description
    JwtCreationOptions jwtOptions

    jwt token creation options which you can modify per request

    object request

    the request dto. maybe null unless you supply it to the CreateTokenWith<TService>(string, Action<UserPrivileges>, TRequest?) method.

    Returns
    Type Description
    Task

    OnBeforeRenewalTokenCreationAsync(JwtCreationOptions, TRequest?)

    a hook for modifying jwt creation options per request when a renewal request comes in. this method is called right before the actual jwt token is created allowing you to override token creation parameters per request if needed.

    Declaration
    public virtual Task OnBeforeRenewalTokenCreationAsync(JwtCreationOptions jwtOptions, TRequest? request)
    Parameters
    Type Name Description
    JwtCreationOptions jwtOptions

    jwt token creation options which you can modify per request

    TRequest request

    the request dto. maybe null unless you supply it to the CreateTokenWith<TService>(string, Action<UserPrivileges>, TRequest?) method.

    Returns
    Type Description
    Task

    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 embedded 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 privileges to be embedded 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

    Implements

    IEndpoint
    IEventBus
    IServiceResolverBase
    In this article
    Back to top Developed by Đĵ ΝιΓΞΗΛψΚ and contributors / Licensed under MIT / Website generated by DocFX