< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Authentication.OidcOptions
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Authentication/OidcOptions.cs
Tag: Kestrun/Kestrun@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
92%
Covered lines: 94
Uncovered lines: 8
Coverable lines: 102
Total lines: 256
Line coverage: 92.1%
Branch coverage
63%
Covered branches: 19
Total branches: 30
Branch coverage: 63.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 11/19/2025 - 02:25:56 Line coverage: 93.7% (90/96) Branch coverage: 76.6% (23/30) Total lines: 216 Tag: Kestrun/Kestrun@98ff905e5605a920343154665980a71211a03c6d12/12/2025 - 17:27:19 Line coverage: 92.5% (99/107) Branch coverage: 67.6% (23/34) Total lines: 256 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd12/15/2025 - 02:23:46 Line coverage: 92.1% (94/102) Branch coverage: 63.3% (19/30) Total lines: 256 Tag: Kestrun/Kestrun@7a3839f4de2254e22daae81ab8dc7cb2f40c8330 11/19/2025 - 02:25:56 Line coverage: 93.7% (90/96) Branch coverage: 76.6% (23/30) Total lines: 216 Tag: Kestrun/Kestrun@98ff905e5605a920343154665980a71211a03c6d12/12/2025 - 17:27:19 Line coverage: 92.5% (99/107) Branch coverage: 67.6% (23/34) Total lines: 256 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd12/15/2025 - 02:23:46 Line coverage: 92.1% (94/102) Branch coverage: 63.3% (19/30) Total lines: 256 Tag: Kestrun/Kestrun@7a3839f4de2254e22daae81ab8dc7cb2f40c8330

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_CookieOptions()100%11100%
get_CookieScheme()100%22100%
get_JwkJson()100%11100%
get_PushedAuthorizationBehavior()100%11100%
get_GlobalScheme()100%11100%
get_Description()100%11100%
get_DisplayName()100%11100%
get_DocumentationId()100%11100%
get_Host()100%11100%
get_Logger()0%2040%
.ctor()100%11100%
get_AuthenticationScheme()100%11100%
get_ClaimPolicy()100%210%
ApplyTo(...)100%11100%
ApplyTo(...)100%11100%
CopyCoreEndpoints(...)100%11100%
CopyFlowConfiguration(...)100%11100%
CopyScopes(...)100%22100%
CopyTokenHandling(...)100%11100%
CopyPaths(...)100%11100%
CopyTokenValidation(...)100%22100%
CopySchemeLinkage(...)100%11100%
CopyBackchannelConfiguration(...)66.66%7671.42%
CopyConfiguration(...)50%5460%
CopyClaimActions(...)66.66%6685.71%
CopyEvents(...)75%4480%
CopyIssuerAndProperties(...)100%11100%

File(s)

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

#LineLine coverage
 1using Kestrun.Claims;
 2using Kestrun.Hosting;
 3using Microsoft.AspNetCore.Authentication;
 4using Microsoft.AspNetCore.Authentication.Cookies;
 5using Microsoft.AspNetCore.Authentication.OpenIdConnect;
 6
 7namespace Kestrun.Authentication;
 8
 9/// <summary>
 10/// Options for OpenID Connect authentication.
 11/// </summary>
 12public class OidcOptions : OpenIdConnectOptions, IOpenApiAuthenticationOptions, IAuthenticationHostOptions, IOAuthCommon
 13{
 14    /// <summary>
 15    /// Options for cookie authentication.
 16    /// </summary>
 517    public CookieAuthOptions CookieOptions { get; }
 18
 19    /// <summary>
 20    /// Gets the cookie authentication scheme name.
 21    /// </summary>
 22    public string CookieScheme =>
 223    CookieOptions.Cookie.Name ?? (CookieAuthenticationDefaults.AuthenticationScheme + "." + AuthenticationScheme);
 24
 25    /// <summary>
 26    /// JSON Web Key (JWK) for token validation.
 27    /// </summary>
 728    public string? JwkJson { get; set; }
 29
 30#if NET8_0
 31    /// <summary>
 32    /// Additional authorization parameters to include in the authorization request.
 33    /// </summary>
 1134    public string PushedAuthorizationBehavior { get; set; } = "Disable";
 35#endif
 36
 37    /// <inheritdoc/>
 238    public bool GlobalScheme { get; set; }
 39
 40    /// <inheritdoc/>
 241    public string? Description { get; set; }
 42
 43    /// <inheritdoc/>
 244    public string? DisplayName { get; set; }
 45
 46    /// <inheritdoc/>
 1347    public string[] DocumentationId { get; set; } = [];
 48
 49    /// <inheritdoc/>
 50#pragma warning disable IDE0370 // Remove unnecessary suppression
 251    public KestrunHost Host { get; set; } = default!;
 52#pragma warning restore IDE0370 // Remove unnecessary suppression
 53
 54    private Serilog.ILogger? _logger;
 55    /// <inheritdoc/>
 56    public Serilog.ILogger Logger
 57    {
 058        get => _logger ?? (Host is null ? Serilog.Log.Logger : Host.Logger); set => _logger = value;
 59    }
 60
 61    /// <summary>
 62    /// Initializes a new instance of the <see cref="OidcOptions"/> class.
 63    /// </summary>
 1164    public OidcOptions()
 65    {
 1166        CookieOptions = new CookieAuthOptions()
 1167        {
 1168            SlidingExpiration = true
 1169        };
 1170    }
 71
 72    /// <summary>
 73    /// Gets or sets the authentication scheme name.
 74    /// </summary>
 1375    public string AuthenticationScheme { get; set; } = AuthenticationDefaults.OidcSchemeName;
 76
 77    /// <summary>
 78    /// Configuration for claim policy enforcement.
 79    /// </summary>
 080    public ClaimPolicyConfig? ClaimPolicy { get; set; }
 81    /// <summary>
 82    /// Helper to copy values from a user-supplied OidcOptions instance to the instance
 83    /// created by the framework inside AddOpenIdConnect().
 84    /// </summary>
 85    /// <param name="target">The target options to copy to.</param>
 86    public void ApplyTo(OidcOptions target)
 87    {
 288        ApplyTo((OpenIdConnectOptions)target);
 189        target.JwkJson = JwkJson;
 90        // OpenAPI / documentation properties
 191        target.GlobalScheme = GlobalScheme;
 192        target.Description = Description;
 193        target.DisplayName = DisplayName;
 194        target.DocumentationId = DocumentationId;
 195        target.Host = Host;
 196    }
 97
 98    /// <summary>
 99    /// Helper to copy values from a user-supplied OpenIdConnectOptions instance to the instance
 100    /// created by the framework inside AddOpenIdConnect().
 101    /// </summary>
 102    /// <param name="target">The target options to copy to.</param>
 103    public void ApplyTo(OpenIdConnectOptions target)
 104    {
 7105        CopyCoreEndpoints(target);
 5106        CopyFlowConfiguration(target);
 5107        CopyScopes(target);
 5108        CopyTokenHandling(target);
 5109        CopyPaths(target);
 5110        CopyTokenValidation(target);
 5111        CopySchemeLinkage(target);
 5112        CopyBackchannelConfiguration(target);
 5113        CopyConfiguration(target);
 5114        CopyClaimActions(target);
 5115        CopyEvents(target);
 5116        CopyIssuerAndProperties(target);
 117#if NET9_0_OR_GREATER
 118        CopyNet9Features(target);
 119#endif
 5120    }
 121
 122    private void CopyCoreEndpoints(OpenIdConnectOptions target)
 123    {
 7124        target.Authority = Authority;
 5125        target.ClientId = ClientId;
 5126        target.ClientSecret = ClientSecret;
 5127    }
 128
 129    private void CopyFlowConfiguration(OpenIdConnectOptions target)
 130    {
 5131        target.ResponseType = ResponseType;
 5132        target.ResponseMode = ResponseMode;
 5133        target.UsePkce = UsePkce;
 5134        target.RequireHttpsMetadata = RequireHttpsMetadata;
 5135    }
 136
 137    private void CopyScopes(OpenIdConnectOptions target)
 138    {
 5139        target.Scope.Clear();
 32140        foreach (var scope in Scope)
 141        {
 11142            target.Scope.Add(scope);
 143        }
 5144    }
 145
 146    private void CopyTokenHandling(OpenIdConnectOptions target)
 147    {
 5148        target.SaveTokens = SaveTokens;
 5149        target.GetClaimsFromUserInfoEndpoint = GetClaimsFromUserInfoEndpoint;
 5150        target.MapInboundClaims = MapInboundClaims;
 5151        target.UseSecurityTokenValidator = UseSecurityTokenValidator;
 5152    }
 153
 154    private void CopyPaths(OpenIdConnectOptions target)
 155    {
 5156        target.CallbackPath = CallbackPath;
 5157        target.SignedOutCallbackPath = SignedOutCallbackPath;
 5158        target.SignedOutRedirectUri = SignedOutRedirectUri;
 5159        target.RemoteSignOutPath = RemoteSignOutPath;
 5160    }
 161
 162    private void CopyTokenValidation(OpenIdConnectOptions target)
 163    {
 5164        if (TokenValidationParameters != null)
 165        {
 5166            target.TokenValidationParameters = TokenValidationParameters;
 167        }
 5168    }
 169
 170    private void CopySchemeLinkage(OpenIdConnectOptions target)
 171    {
 5172        target.SignInScheme = SignInScheme;
 5173        target.SignOutScheme = SignOutScheme;
 5174    }
 175
 176    private void CopyBackchannelConfiguration(OpenIdConnectOptions target)
 177    {
 5178        if (Backchannel != null)
 179        {
 0180            target.Backchannel = Backchannel;
 181        }
 5182        if (BackchannelHttpHandler != null)
 183        {
 0184            target.BackchannelHttpHandler = BackchannelHttpHandler;
 185        }
 5186        if (BackchannelTimeout != default)
 187        {
 5188            target.BackchannelTimeout = BackchannelTimeout;
 189        }
 5190    }
 191
 192    private void CopyConfiguration(OpenIdConnectOptions target)
 193    {
 5194        if (Configuration != null)
 195        {
 0196            target.Configuration = Configuration;
 197        }
 5198        if (ConfigurationManager != null)
 199        {
 0200            target.ConfigurationManager = ConfigurationManager;
 201        }
 5202    }
 203
 204    private void CopyClaimActions(OpenIdConnectOptions target)
 205    {
 5206        if (ClaimActions == null)
 207        {
 0208            return;
 209        }
 74210        foreach (var jka in ClaimActions
 5211            .OfType<Microsoft.AspNetCore.Authentication.OAuth.Claims.JsonKeyClaimAction>()
 37212            .Where(a => !string.IsNullOrEmpty(a.JsonKey) && !string.IsNullOrEmpty(a.ClaimType)))
 213        {
 32214            target.ClaimActions.MapJsonKey(jka.ClaimType, jka.JsonKey);
 215        }
 5216    }
 217
 218    private void CopyEvents(OpenIdConnectOptions target)
 219    {
 5220        if (Events != null)
 221        {
 5222            target.Events = Events;
 223        }
 5224        if (EventsType != null)
 225        {
 0226            target.EventsType = EventsType;
 227        }
 5228    }
 229
 230    private void CopyIssuerAndProperties(OpenIdConnectOptions target)
 231    {
 5232        target.ClaimsIssuer = ClaimsIssuer;
 5233        target.DisableTelemetry = DisableTelemetry;
 5234        target.MaxAge = MaxAge;
 5235        target.ProtocolValidator = ProtocolValidator;
 5236        target.RefreshOnIssuerKeyNotFound = RefreshOnIssuerKeyNotFound;
 5237        target.Resource = Resource;
 5238        target.SkipUnrecognizedRequests = SkipUnrecognizedRequests;
 5239        target.StateDataFormat = StateDataFormat;
 5240        target.StringDataFormat = StringDataFormat;
 5241    }
 242
 243#if NET9_0_OR_GREATER
 244    private void CopyNet9Features(OpenIdConnectOptions target)
 245    {
 246        target.PushedAuthorizationBehavior = PushedAuthorizationBehavior;
 247        if (AdditionalAuthorizationParameters != null)
 248        {
 249            foreach (var param in AdditionalAuthorizationParameters)
 250            {
 251                target.AdditionalAuthorizationParameters[param.Key] = param.Value;
 252            }
 253        }
 254    }
 255#endif
 256}