< 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@ca54e35c77799b76774b3805b6f075cdbc0c5fbe
Line coverage
91%
Covered lines: 94
Uncovered lines: 9
Coverable lines: 103
Total lines: 260
Line coverage: 91.2%
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@7a3839f4de2254e22daae81ab8dc7cb2f40c833012/21/2025 - 06:07:10 Line coverage: 91.2% (94/103) Branch coverage: 63.3% (19/30) Total lines: 260 Tag: Kestrun/Kestrun@8cf7f77e55fd1fd046ea4e5413eb9ef96e49fe6a 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@7a3839f4de2254e22daae81ab8dc7cb2f40c833012/21/2025 - 06:07:10 Line coverage: 91.2% (94/103) Branch coverage: 63.3% (19/30) Total lines: 260 Tag: Kestrun/Kestrun@8cf7f77e55fd1fd046ea4e5413eb9ef96e49fe6a

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%
get_Deprecated()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
 82    /// <inheritdoc/>
 083    public bool Deprecated { get; set; }
 84
 85    /// <summary>
 86    /// Helper to copy values from a user-supplied OidcOptions instance to the instance
 87    /// created by the framework inside AddOpenIdConnect().
 88    /// </summary>
 89    /// <param name="target">The target options to copy to.</param>
 90    public void ApplyTo(OidcOptions target)
 91    {
 292        ApplyTo((OpenIdConnectOptions)target);
 193        target.JwkJson = JwkJson;
 94        // OpenAPI / documentation properties
 195        target.GlobalScheme = GlobalScheme;
 196        target.Description = Description;
 197        target.DisplayName = DisplayName;
 198        target.DocumentationId = DocumentationId;
 199        target.Host = Host;
 1100    }
 101
 102    /// <summary>
 103    /// Helper to copy values from a user-supplied OpenIdConnectOptions instance to the instance
 104    /// created by the framework inside AddOpenIdConnect().
 105    /// </summary>
 106    /// <param name="target">The target options to copy to.</param>
 107    public void ApplyTo(OpenIdConnectOptions target)
 108    {
 7109        CopyCoreEndpoints(target);
 5110        CopyFlowConfiguration(target);
 5111        CopyScopes(target);
 5112        CopyTokenHandling(target);
 5113        CopyPaths(target);
 5114        CopyTokenValidation(target);
 5115        CopySchemeLinkage(target);
 5116        CopyBackchannelConfiguration(target);
 5117        CopyConfiguration(target);
 5118        CopyClaimActions(target);
 5119        CopyEvents(target);
 5120        CopyIssuerAndProperties(target);
 121#if NET9_0_OR_GREATER
 122        CopyNet9Features(target);
 123#endif
 5124    }
 125
 126    private void CopyCoreEndpoints(OpenIdConnectOptions target)
 127    {
 7128        target.Authority = Authority;
 5129        target.ClientId = ClientId;
 5130        target.ClientSecret = ClientSecret;
 5131    }
 132
 133    private void CopyFlowConfiguration(OpenIdConnectOptions target)
 134    {
 5135        target.ResponseType = ResponseType;
 5136        target.ResponseMode = ResponseMode;
 5137        target.UsePkce = UsePkce;
 5138        target.RequireHttpsMetadata = RequireHttpsMetadata;
 5139    }
 140
 141    private void CopyScopes(OpenIdConnectOptions target)
 142    {
 5143        target.Scope.Clear();
 32144        foreach (var scope in Scope)
 145        {
 11146            target.Scope.Add(scope);
 147        }
 5148    }
 149
 150    private void CopyTokenHandling(OpenIdConnectOptions target)
 151    {
 5152        target.SaveTokens = SaveTokens;
 5153        target.GetClaimsFromUserInfoEndpoint = GetClaimsFromUserInfoEndpoint;
 5154        target.MapInboundClaims = MapInboundClaims;
 5155        target.UseSecurityTokenValidator = UseSecurityTokenValidator;
 5156    }
 157
 158    private void CopyPaths(OpenIdConnectOptions target)
 159    {
 5160        target.CallbackPath = CallbackPath;
 5161        target.SignedOutCallbackPath = SignedOutCallbackPath;
 5162        target.SignedOutRedirectUri = SignedOutRedirectUri;
 5163        target.RemoteSignOutPath = RemoteSignOutPath;
 5164    }
 165
 166    private void CopyTokenValidation(OpenIdConnectOptions target)
 167    {
 5168        if (TokenValidationParameters != null)
 169        {
 5170            target.TokenValidationParameters = TokenValidationParameters;
 171        }
 5172    }
 173
 174    private void CopySchemeLinkage(OpenIdConnectOptions target)
 175    {
 5176        target.SignInScheme = SignInScheme;
 5177        target.SignOutScheme = SignOutScheme;
 5178    }
 179
 180    private void CopyBackchannelConfiguration(OpenIdConnectOptions target)
 181    {
 5182        if (Backchannel != null)
 183        {
 0184            target.Backchannel = Backchannel;
 185        }
 5186        if (BackchannelHttpHandler != null)
 187        {
 0188            target.BackchannelHttpHandler = BackchannelHttpHandler;
 189        }
 5190        if (BackchannelTimeout != default)
 191        {
 5192            target.BackchannelTimeout = BackchannelTimeout;
 193        }
 5194    }
 195
 196    private void CopyConfiguration(OpenIdConnectOptions target)
 197    {
 5198        if (Configuration != null)
 199        {
 0200            target.Configuration = Configuration;
 201        }
 5202        if (ConfigurationManager != null)
 203        {
 0204            target.ConfigurationManager = ConfigurationManager;
 205        }
 5206    }
 207
 208    private void CopyClaimActions(OpenIdConnectOptions target)
 209    {
 5210        if (ClaimActions == null)
 211        {
 0212            return;
 213        }
 74214        foreach (var jka in ClaimActions
 5215            .OfType<Microsoft.AspNetCore.Authentication.OAuth.Claims.JsonKeyClaimAction>()
 37216            .Where(a => !string.IsNullOrEmpty(a.JsonKey) && !string.IsNullOrEmpty(a.ClaimType)))
 217        {
 32218            target.ClaimActions.MapJsonKey(jka.ClaimType, jka.JsonKey);
 219        }
 5220    }
 221
 222    private void CopyEvents(OpenIdConnectOptions target)
 223    {
 5224        if (Events != null)
 225        {
 5226            target.Events = Events;
 227        }
 5228        if (EventsType != null)
 229        {
 0230            target.EventsType = EventsType;
 231        }
 5232    }
 233
 234    private void CopyIssuerAndProperties(OpenIdConnectOptions target)
 235    {
 5236        target.ClaimsIssuer = ClaimsIssuer;
 5237        target.DisableTelemetry = DisableTelemetry;
 5238        target.MaxAge = MaxAge;
 5239        target.ProtocolValidator = ProtocolValidator;
 5240        target.RefreshOnIssuerKeyNotFound = RefreshOnIssuerKeyNotFound;
 5241        target.Resource = Resource;
 5242        target.SkipUnrecognizedRequests = SkipUnrecognizedRequests;
 5243        target.StateDataFormat = StateDataFormat;
 5244        target.StringDataFormat = StringDataFormat;
 5245    }
 246
 247#if NET9_0_OR_GREATER
 248    private void CopyNet9Features(OpenIdConnectOptions target)
 249    {
 250        target.PushedAuthorizationBehavior = PushedAuthorizationBehavior;
 251        if (AdditionalAuthorizationParameters != null)
 252        {
 253            foreach (var param in AdditionalAuthorizationParameters)
 254            {
 255                target.AdditionalAuthorizationParameters[param.Key] = param.Value;
 256            }
 257        }
 258    }
 259#endif
 260}