< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Authentication.JwtAuthOptions
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Authentication/JwtAuthOptions.cs
Tag: Kestrun/Kestrun@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
93%
Covered lines: 29
Uncovered lines: 2
Coverable lines: 31
Total lines: 113
Line coverage: 93.5%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 12/12/2025 - 17:27:19 Line coverage: 93.5% (29/31) Branch coverage: 0% (0/4) Total lines: 113 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd 12/12/2025 - 17:27:19 Line coverage: 93.5% (29/31) Branch coverage: 0% (0/4) Total lines: 113 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_AllowInsecureHttp()100%210%
get_Logger()0%2040%
get_ValidationParameters()100%11100%
get_DisplayName()100%11100%
get_GlobalScheme()100%11100%
get_Description()100%11100%
get_DocumentationId()100%11100%
get_Host()100%11100%
get_ClaimPolicy()100%11100%
get_IssueClaims()100%11100%
get_IssueClaimsCodeSettings()100%11100%
get_ClaimPolicyConfig()100%11100%
ApplyTo(...)100%11100%
ApplyTo(...)100%11100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Authentication/JwtAuthOptions.cs

#LineLine coverage
 1using System.Security.Claims;
 2using Kestrun.Claims;
 3using Kestrun.Hosting;
 4using Microsoft.AspNetCore.Authentication.JwtBearer;
 5using Microsoft.IdentityModel.Tokens;
 6
 7namespace Kestrun.Authentication;
 8
 9/// <summary>
 10/// Options for JWT-based authentication.
 11/// </summary>
 12public class JwtAuthOptions : JwtBearerOptions, IOpenApiAuthenticationOptions, IClaimsCommonOptions, IAuthenticationHost
 13{
 14    /// <summary>
 15    /// If true, allows cookie authentication over insecure HTTP connections.
 16    /// </summary>
 017    public bool AllowInsecureHttp { get; set; }
 18
 19    private Serilog.ILogger? _logger;
 20    /// <inheritdoc/>
 21    public Serilog.ILogger Logger
 22    {
 023        get => _logger ?? (Host is null ? Serilog.Log.Logger : Host.Logger); set => _logger = value;
 24    }
 25
 26    /// <summary>
 27    /// Gets or sets the token validation parameters.
 28    /// </summary>
 229    public TokenValidationParameters? ValidationParameters { get; set; }
 30
 31    /// <inheritdoc/>
 632    public string? DisplayName { get; set; }
 33
 34    /// <inheritdoc/>
 935    public bool GlobalScheme { get; set; }
 36
 37    /// <inheritdoc/>
 938    public string? Description { get; set; }
 39
 40    /// <inheritdoc/>
 3041    public string[] DocumentationId { get; set; } = [];
 42
 43    /// <inheritdoc/>
 1544    public KestrunHost Host { get; set; } = default!;
 45
 46    /// <summary>
 47    /// Configuration for claim policy enforcement.
 48    /// </summary>
 1349    public ClaimPolicyConfig? ClaimPolicy { get; set; }
 50
 51    /// <summary>
 52    /// After credentials are valid, this is called to add extra Claims.
 53    /// Parameters: HttpContext, username → IEnumerable of extra claims.
 54    /// </summary>
 355    public Func<HttpContext, string, Task<IEnumerable<Claim>>>? IssueClaims { get; set; }
 56
 57    /// <summary>
 58    /// Settings for the claims issuing code, if using a script.
 59    /// </summary>
 60    /// <remarks>
 61    /// This allows you to specify the language, code, and additional imports/refs for claims issuance.
 62    /// </remarks>
 1363    public AuthenticationCodeSettings IssueClaimsCodeSettings { get; set; } = new();
 64
 65    /// <summary>
 66    /// Gets or sets the claim policy configuration.
 67    /// </summary>
 68    /// <remarks>
 69    /// This allows you to define multiple authorization policies based on claims.
 70    /// Each policy can specify a claim type and allowed values.
 71    /// </remarks>
 272    public ClaimPolicyConfig? ClaimPolicyConfig { get; set; }
 73
 74    /// <summary>
 75    /// Helper to copy values from a user-supplied JwtBearerOptions instance to the instance
 76    /// created by the framework inside AddJwtBearer(). Reassigning the local variable (opts = source) would
 77    /// not work because only the local reference changes – the framework keeps the original instance.
 78    /// </summary>
 79    /// <param name="target">The target options to copy to.</param>
 80    /// <exception cref="ArgumentNullException">Thrown when source or target is null.</exception>
 81    /// <remarks>
 82    /// Only copies primitive properties and references. Does not clone complex objects like CookieBuilder.
 83    /// </remarks>
 84    public void ApplyTo(JwtAuthOptions target)
 85    {
 386        ApplyTo((JwtBearerOptions)target);
 387        target.GlobalScheme = GlobalScheme;
 388        target.Description = Description;
 389        target.DocumentationId = DocumentationId;
 390        target.DisplayName = DisplayName;
 391        target.Host = Host;
 392        target.ClaimPolicy = ClaimPolicy;
 393    }
 94
 95    /// <summary>
 96    /// Helper to copy values from this JwtAuthOptions instance to a target JwtBearerOptions instance.
 97    /// </summary>
 98    /// <param name="target">The target JwtBearerOptions instance to copy values to.</param>
 99    public void ApplyTo(JwtBearerOptions target)
 100    {
 101        // Paths & return URL
 3102        target.TokenValidationParameters = TokenValidationParameters;
 3103        target.MapInboundClaims = MapInboundClaims;
 3104        target.SaveToken = SaveToken;
 3105        target.IncludeErrorDetails = IncludeErrorDetails;
 3106        target.RefreshOnIssuerKeyNotFound = RefreshOnIssuerKeyNotFound;
 3107        target.RequireHttpsMetadata = RequireHttpsMetadata;
 3108        target.MetadataAddress = MetadataAddress;
 3109        target.Authority = Authority;
 3110        target.Audience = Audience;
 3111        target.Challenge = Challenge;
 3112    }
 113}