< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.WebApi.Security.PersonTokenValidator
Assembly: ArturRios.Heimdall.WebApi
File(s): /home/runner/work/heimdall-api/heimdall-api/src/Presentation/ArturRios.Heimdall.WebApi/Security/PersonTokenValidator.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 49
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage
100%
Covered methods: 2
Fully covered methods: 2
Total methods: 2
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ValidateAsync()100%44100%

File(s)

/home/runner/work/heimdall-api/heimdall-api/src/Presentation/ArturRios.Heimdall.WebApi/Security/PersonTokenValidator.cs

#LineLine coverage
 1using ArturRios.Jwt;
 2using ArturRios.Util.WebApi.Security.Authentication;
 3using ArturRios.Util.WebApi.Security.Interfaces;
 4using ArturRios.Util.WebApi.Security.Records;
 5
 6namespace ArturRios.Heimdall.WebApi.Security;
 7
 8/// <summary>
 9///     The bearer-token validator <c>AuthenticationMiddleware</c> runs: the library's
 10///     <see cref="JwtTokenValidator" />, which checks the signature and lifetime and maps the claims,
 11///     followed by the issuer and audience check it does not make (<see cref="TokenOrigin" />).
 12/// </summary>
 13/// <remarks>
 14///     <para>
 15///         A token passes only under the configured issuer and one of the three person audiences
 16///         (<see cref="PersonTokenAudiences" />). The challenge audience is among them so that
 17///         <see cref="MfaPendingGuardFilter" /> still answers a challenge used as a bearer token with
 18///         its own refusal; the application audience is not, since an application token is never a
 19///         person (TH-35).
 20///     </para>
 21///     <para>
 22///         A token refused here gets the answer a bad signature gets, so a correctly signed token for
 23///         another service cannot be told apart from a forged one.
 24///     </para>
 25/// </remarks>
 91126public sealed class PersonTokenValidator(
 91127    JwtTokenValidator inner,
 91128    JwtConfiguration configuration,
 91129    PersonTokenAudiences audiences) : ITokenValidator
 30{
 31    /// <summary>The error <see cref="JwtTokenValidator" /> gives a token whose signature or lifetime fails.</summary>
 32    public const string InvalidToken = "Invalid token";
 33
 34    /// <inheritdoc />
 35    public async Task<TokenValidationResult> ValidateAsync(string token, HttpContext context)
 36    {
 104837        var result = await inner.ValidateAsync(token, context);
 38
 104839        if (result.User is null)
 40        {
 10041            return result;
 42        }
 43
 94844        return TokenOrigin.IsIssuedFor(
 94845            token, configuration.Issuer, audiences.Person, audiences.TwoFactorChallenge, audiences.SubjectRights)
 94846            ? result
 94847            : new TokenValidationResult(null, InvalidToken);
 104848    }
 49}