< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Authentication.OAuth2Options
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Authentication/OAuth2Options.cs
Tag: Kestrun/Kestrun@ca54e35c77799b76774b3805b6f075cdbc0c5fbe
Line coverage
70%
Covered lines: 42
Uncovered lines: 18
Coverable lines: 60
Total lines: 165
Line coverage: 70%
Branch coverage
66%
Covered branches: 16
Total branches: 24
Branch coverage: 66.6%
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% (40/43) Branch coverage: 80% (16/20) Total lines: 107 Tag: Kestrun/Kestrun@98ff905e5605a920343154665980a71211a03c6d12/12/2025 - 17:27:19 Line coverage: 73.6% (42/57) Branch coverage: 66.6% (16/24) Total lines: 160 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd12/21/2025 - 06:07:10 Line coverage: 70% (42/60) Branch coverage: 66.6% (16/24) Total lines: 165 Tag: Kestrun/Kestrun@8cf7f77e55fd1fd046ea4e5413eb9ef96e49fe6a 11/19/2025 - 02:25:56 Line coverage: 93% (40/43) Branch coverage: 80% (16/20) Total lines: 107 Tag: Kestrun/Kestrun@98ff905e5605a920343154665980a71211a03c6d12/12/2025 - 17:27:19 Line coverage: 73.6% (42/57) Branch coverage: 66.6% (16/24) Total lines: 160 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd12/21/2025 - 06:07:10 Line coverage: 70% (42/60) Branch coverage: 66.6% (16/24) Total lines: 165 Tag: Kestrun/Kestrun@8cf7f77e55fd1fd046ea4e5413eb9ef96e49fe6a

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_CookieOptions()100%11100%
get_GlobalScheme()100%210%
get_Description()100%210%
get_DisplayName()100%210%
get_Deprecated()100%210%
get_DocumentationId()100%11100%
get_Host()100%210%
.ctor()100%11100%
get_AuthenticationScheme()100%11100%
get_CookieScheme()100%22100%
get_ClaimPolicy()100%11100%
get_Logger()0%2040%
ApplyTo(...)100%2110%
ApplyTo(...)77.77%181890.9%

File(s)

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

#LineLine coverage
 1
 2using Kestrun.Claims;
 3using Kestrun.Hosting;
 4using Microsoft.AspNetCore.Authentication;
 5using Microsoft.AspNetCore.Authentication.Cookies;
 6using Microsoft.AspNetCore.Authentication.OAuth;
 7
 8namespace Kestrun.Authentication;
 9
 10/// <summary>
 11/// Options for OAuth2 authentication.
 12/// </summary>
 13public class OAuth2Options : OAuthOptions, IOpenApiAuthenticationOptions, IAuthenticationHostOptions, IOAuthCommonOption
 14{
 15    /// <summary>
 16    /// Options for cookie authentication.
 17    /// </summary>
 518    public CookieAuthOptions CookieOptions { get; }
 19
 20    /// <inheritdoc/>
 021    public bool GlobalScheme { get; set; }
 22
 23    /// <inheritdoc/>
 024    public string? Description { get; set; }
 25
 26    /// <inheritdoc/>
 027    public string? DisplayName { get; set; }
 28
 29    /// <inheritdoc/>
 030    public bool Deprecated { get; set; }
 31
 32    /// <inheritdoc/>
 1233    public string[] DocumentationId { get; set; } = [];
 34
 35#pragma warning disable IDE0370 // Remove unnecessary suppression
 36    /// <inheritdoc/>
 037    public KestrunHost Host { get; set; } = default!;
 38#pragma warning restore IDE0370 // Remove unnecessary suppression
 39
 40    /// <summary>
 41    /// Initializes a new instance of the <see cref="OAuth2Options"/> class.
 42    /// </summary>
 1243    public OAuth2Options()
 44    {
 1245        CookieOptions = new CookieAuthOptions()
 1246        {
 1247            SlidingExpiration = true
 1248        };
 1249    }
 50    /// <summary>
 51    /// Gets or sets the authentication scheme name.
 52    /// </summary>
 1353    public string AuthenticationScheme { get; set; } = AuthenticationDefaults.OAuth2SchemeName;
 54
 55    /// <summary>
 56    /// Gets the cookie authentication scheme name.
 57    /// </summary>
 58    public string CookieScheme =>
 259    CookieOptions.Cookie.Name ?? (CookieAuthenticationDefaults.AuthenticationScheme + "." + AuthenticationScheme);
 60
 61    /// <summary>
 62    /// Configuration for claim policy enforcement.
 63    /// </summary>
 1064    public ClaimPolicyConfig? ClaimPolicy { get; set; }
 65
 66    private Serilog.ILogger? _logger;
 67    /// <inheritdoc/>
 68    public Serilog.ILogger Logger
 69    {
 070        get => _logger ?? (Host is null ? Serilog.Log.Logger : Host.Logger); set => _logger = value;
 71    }
 72
 73    /// <summary>
 74    /// Helper to copy values from a user-supplied OAuth2Options instance to the instance
 75    /// created by the framework inside AddOAuth(). Reassigning the local variable (opts = source) would
 76    /// not work because only the local reference changes – the framework keeps the original instance.
 77    /// </summary>
 78    /// <param name="target">The target OAuth2Options instance to copy values to.</param>
 79    public void ApplyTo(OAuth2Options target)
 80    {
 181        ApplyTo((OAuthOptions)target);
 082        CookieOptions.ApplyTo(target.CookieOptions);
 83        // OpenAPI / documentation properties
 084        target.GlobalScheme = GlobalScheme;
 085        target.Description = Description;
 086        target.DisplayName = DisplayName;
 087        target.DocumentationId = DocumentationId;
 088        target.Host = Host;
 089        target.ClaimPolicy = ClaimPolicy;
 090        target.Deprecated = Deprecated;
 091    }
 92
 93    /// <summary>
 94    /// Apply these options to the target <see cref="OAuthOptions"/> instance.
 95    /// </summary>
 96    /// <param name="target">The target OAuthOptions instance to apply settings to.</param>
 97    public void ApplyTo(OAuthOptions target)
 98    {
 99        // Core OAuth endpoints
 6100        target.AuthorizationEndpoint = AuthorizationEndpoint;
 5101        target.TokenEndpoint = TokenEndpoint;
 5102        target.UserInformationEndpoint = UserInformationEndpoint;
 5103        target.ClientId = ClientId;
 5104        target.ClientSecret = ClientSecret;
 5105        target.CallbackPath = CallbackPath;
 106
 107        // OAuth configuration
 5108        target.UsePkce = UsePkce;
 5109        target.SaveTokens = SaveTokens;
 5110        target.ClaimsIssuer = ClaimsIssuer;
 111
 112        // Scopes - clear and copy
 5113        target.Scope.Clear();
 14114        foreach (var scope in Scope)
 115        {
 2116            target.Scope.Add(scope);
 117        }
 118
 119        // Token handling
 5120        target.AccessDeniedPath = AccessDeniedPath;
 5121        target.RemoteAuthenticationTimeout = RemoteAuthenticationTimeout;
 5122        target.ReturnUrlParameter = ReturnUrlParameter;
 123
 124        // Scheme linkage
 5125        target.SignInScheme = SignInScheme;
 126
 127        // Backchannel configuration
 5128        if (Backchannel != null)
 129        {
 0130            target.Backchannel = Backchannel;
 131        }
 5132        if (BackchannelHttpHandler != null)
 133        {
 0134            target.BackchannelHttpHandler = BackchannelHttpHandler;
 135        }
 5136        if (BackchannelTimeout != default)
 137        {
 5138            target.BackchannelTimeout = BackchannelTimeout;
 139        }
 140
 141        // Claim actions
 5142        if (ClaimActions != null)
 143        {
 14144            foreach (var jka in ClaimActions
 5145                .OfType<Microsoft.AspNetCore.Authentication.OAuth.Claims.JsonKeyClaimAction>()
 7146                .Where(a => !string.IsNullOrEmpty(a.JsonKey) && !string.IsNullOrEmpty(a.ClaimType)))
 147            {
 2148                target.ClaimActions.MapJsonKey(jka.ClaimType, jka.JsonKey);
 149            }
 150        }
 151
 152        // Events - copy if provided
 5153        if (Events != null)
 154        {
 5155            target.Events = Events;
 156        }
 5157        if (EventsType != null)
 158        {
 0159            target.EventsType = EventsType;
 160        }
 161
 162        // Other properties
 5163        target.StateDataFormat = StateDataFormat;
 5164    }
 165}