< 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@ca54e35c77799b76774b3805b6f075cdbc0c5fbe
Line coverage
94%
Covered lines: 33
Uncovered lines: 2
Coverable lines: 35
Total lines: 119
Line coverage: 94.2%
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@826bf9dcf9db118c5de4c78a3259bce9549f0dcd12/21/2025 - 06:07:10 Line coverage: 94.2% (33/35) Branch coverage: 0% (0/4) Total lines: 119 Tag: Kestrun/Kestrun@8cf7f77e55fd1fd046ea4e5413eb9ef96e49fe6a 12/12/2025 - 17:27:19 Line coverage: 93.5% (29/31) Branch coverage: 0% (0/4) Total lines: 113 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd12/21/2025 - 06:07:10 Line coverage: 94.2% (33/35) Branch coverage: 0% (0/4) Total lines: 119 Tag: Kestrun/Kestrun@8cf7f77e55fd1fd046ea4e5413eb9ef96e49fe6a

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_Deprecated()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/>
 944    public bool Deprecated { get; set; }
 45
 46    /// <inheritdoc/>
 1547    public KestrunHost Host { get; set; } = default!;
 48
 49    /// <summary>
 50    /// Configuration for claim policy enforcement.
 51    /// </summary>
 1352    public ClaimPolicyConfig? ClaimPolicy { get; set; }
 53
 54    /// <summary>
 55    /// After credentials are valid, this is called to add extra Claims.
 56    /// Parameters: HttpContext, username → IEnumerable of extra claims.
 57    /// </summary>
 958    public Func<HttpContext, string, Task<IEnumerable<Claim>>>? IssueClaims { get; set; }
 59
 60    /// <summary>
 61    /// Settings for the claims issuing code, if using a script.
 62    /// </summary>
 63    /// <remarks>
 64    /// This allows you to specify the language, code, and additional imports/refs for claims issuance.
 65    /// </remarks>
 1966    public AuthenticationCodeSettings IssueClaimsCodeSettings { get; set; } = new();
 67
 68    /// <summary>
 69    /// Gets or sets the claim policy configuration.
 70    /// </summary>
 71    /// <remarks>
 72    /// This allows you to define multiple authorization policies based on claims.
 73    /// Each policy can specify a claim type and allowed values.
 74    /// </remarks>
 275    public ClaimPolicyConfig? ClaimPolicyConfig { get; set; }
 76
 77    /// <summary>
 78    /// Helper to copy values from a user-supplied JwtBearerOptions instance to the instance
 79    /// created by the framework inside AddJwtBearer(). Reassigning the local variable (opts = source) would
 80    /// not work because only the local reference changes – the framework keeps the original instance.
 81    /// </summary>
 82    /// <param name="target">The target options to copy to.</param>
 83    /// <exception cref="ArgumentNullException">Thrown when source or target is null.</exception>
 84    /// <remarks>
 85    /// Only copies primitive properties and references. Does not clone complex objects like CookieBuilder.
 86    /// </remarks>
 87    public void ApplyTo(JwtAuthOptions target)
 88    {
 389        ApplyTo((JwtBearerOptions)target);
 390        target.GlobalScheme = GlobalScheme;
 391        target.Description = Description;
 392        target.DocumentationId = DocumentationId;
 393        target.DisplayName = DisplayName;
 394        target.Host = Host;
 395        target.ClaimPolicy = ClaimPolicy;
 396        target.IssueClaims = IssueClaims;
 397        target.IssueClaimsCodeSettings = IssueClaimsCodeSettings;
 398        target.Deprecated = Deprecated;
 399    }
 100
 101    /// <summary>
 102    /// Helper to copy values from this JwtAuthOptions instance to a target JwtBearerOptions instance.
 103    /// </summary>
 104    /// <param name="target">The target JwtBearerOptions instance to copy values to.</param>
 105    public void ApplyTo(JwtBearerOptions target)
 106    {
 107        // Paths & return URL
 3108        target.TokenValidationParameters = TokenValidationParameters;
 3109        target.MapInboundClaims = MapInboundClaims;
 3110        target.SaveToken = SaveToken;
 3111        target.IncludeErrorDetails = IncludeErrorDetails;
 3112        target.RefreshOnIssuerKeyNotFound = RefreshOnIssuerKeyNotFound;
 3113        target.RequireHttpsMetadata = RequireHttpsMetadata;
 3114        target.MetadataAddress = MetadataAddress;
 3115        target.Authority = Authority;
 3116        target.Audience = Audience;
 3117        target.Challenge = Challenge;
 3118    }
 119}