< Summary

Information
Class: Elsa.Identity.Endpoints.RefreshToken.RefreshToken
Assembly: Elsa.Identity
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Endpoints/RefreshToken/Endpoint.cs
Line coverage
50%
Covered lines: 6
Uncovered lines: 6
Coverable lines: 12
Total lines: 43
Line coverage: 50%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Configure()100%11100%
ExecuteAsync()0%620%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Endpoints/RefreshToken/Endpoint.cs

#LineLine coverage
 1using Elsa.Extensions;
 2using Elsa.Identity.Contracts;
 3using Elsa.Identity.Models;
 4using FastEndpoints;
 5using JetBrains.Annotations;
 6
 7namespace Elsa.Identity.Endpoints.RefreshToken;
 8
 9/// <summary>
 10/// Generates a new token for the current user.
 11/// </summary>
 12[PublicAPI]
 13internal class RefreshToken : EndpointWithoutRequest<LoginResponse>
 14{
 15    private readonly IUserProvider _userProvider;
 16    private readonly IAccessTokenIssuer _tokenIssuer;
 17
 18    /// <inheritdoc />
 119    public RefreshToken(IUserProvider userProvider, IAccessTokenIssuer tokenIssuer)
 20    {
 121        _userProvider = userProvider;
 122        _tokenIssuer = tokenIssuer;
 123    }
 24
 25    /// <inheritdoc />
 26    public override void Configure()
 27    {
 128        Post("/identity/refresh-token");
 129    }
 30
 31    /// <inheritdoc />
 32    public override async Task<LoginResponse> ExecuteAsync(CancellationToken cancellationToken)
 33    {
 034        var user = await _userProvider.FindByNameAsync(User.Identity!.Name!, cancellationToken);
 35
 036        if (user == null)
 037            return new LoginResponse(false, null, null);
 38
 039        var tokens = await _tokenIssuer.IssueTokensAsync(user, cancellationToken);
 40
 041        return new LoginResponse(true, tokens.AccessToken, tokens.RefreshToken);
 042    }
 43}