< 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@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
73%
Covered lines: 42
Uncovered lines: 15
Coverable lines: 57
Total lines: 160
Line coverage: 73.6%
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@826bf9dcf9db118c5de4c78a3259bce9549f0dcd 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@826bf9dcf9db118c5de4c78a3259bce9549f0dcd

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_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%2112.5%
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/>
 1230    public string[] DocumentationId { get; set; } = [];
 31
 32    /// <inheritdoc/>
 33#pragma warning disable IDE0370 // Remove unnecessary suppression
 034    public KestrunHost Host { get; set; } = default!;
 35#pragma warning restore IDE0370 // Remove unnecessary suppression
 36
 37    /// <summary>
 38    /// Initializes a new instance of the <see cref="OAuth2Options"/> class.
 39    /// </summary>
 1240    public OAuth2Options()
 41    {
 1242        CookieOptions = new CookieAuthOptions()
 1243        {
 1244            SlidingExpiration = true
 1245        };
 1246    }
 47    /// <summary>
 48    /// Gets or sets the authentication scheme name.
 49    /// </summary>
 1350    public string AuthenticationScheme { get; set; } = AuthenticationDefaults.OAuth2SchemeName;
 51
 52    /// <summary>
 53    /// Gets the cookie authentication scheme name.
 54    /// </summary>
 55    public string CookieScheme =>
 256    CookieOptions.Cookie.Name ?? (CookieAuthenticationDefaults.AuthenticationScheme + "." + AuthenticationScheme);
 57
 58    /// <summary>
 59    /// Configuration for claim policy enforcement.
 60    /// </summary>
 1061    public ClaimPolicyConfig? ClaimPolicy { get; set; }
 62
 63    private Serilog.ILogger? _logger;
 64    /// <inheritdoc/>
 65    public Serilog.ILogger Logger
 66    {
 067        get => _logger ?? (Host is null ? Serilog.Log.Logger : Host.Logger); set => _logger = value;
 68    }
 69
 70    /// <summary>
 71    /// Helper to copy values from a user-supplied OAuth2Options instance to the instance
 72    /// created by the framework inside AddOAuth(). Reassigning the local variable (opts = source) would
 73    /// not work because only the local reference changes – the framework keeps the original instance.
 74    /// </summary>
 75    /// <param name="target">The target OAuth2Options instance to copy values to.</param>
 76    public void ApplyTo(OAuth2Options target)
 77    {
 178        ApplyTo((OAuthOptions)target);
 079        CookieOptions.ApplyTo(target.CookieOptions);
 80        // OpenAPI / documentation properties
 081        target.GlobalScheme = GlobalScheme;
 082        target.Description = Description;
 083        target.DisplayName = DisplayName;
 084        target.DocumentationId = DocumentationId;
 085        target.Host = Host;
 086    }
 87
 88    /// <summary>
 89    /// Apply these options to the target <see cref="OAuthOptions"/> instance.
 90    /// </summary>
 91    /// <param name="target">The target OAuthOptions instance to apply settings to.</param>
 92    public void ApplyTo(OAuthOptions target)
 93    {
 94        // Core OAuth endpoints
 695        target.AuthorizationEndpoint = AuthorizationEndpoint;
 596        target.TokenEndpoint = TokenEndpoint;
 597        target.UserInformationEndpoint = UserInformationEndpoint;
 598        target.ClientId = ClientId;
 599        target.ClientSecret = ClientSecret;
 5100        target.CallbackPath = CallbackPath;
 101
 102        // OAuth configuration
 5103        target.UsePkce = UsePkce;
 5104        target.SaveTokens = SaveTokens;
 5105        target.ClaimsIssuer = ClaimsIssuer;
 106
 107        // Scopes - clear and copy
 5108        target.Scope.Clear();
 14109        foreach (var scope in Scope)
 110        {
 2111            target.Scope.Add(scope);
 112        }
 113
 114        // Token handling
 5115        target.AccessDeniedPath = AccessDeniedPath;
 5116        target.RemoteAuthenticationTimeout = RemoteAuthenticationTimeout;
 5117        target.ReturnUrlParameter = ReturnUrlParameter;
 118
 119        // Scheme linkage
 5120        target.SignInScheme = SignInScheme;
 121
 122        // Backchannel configuration
 5123        if (Backchannel != null)
 124        {
 0125            target.Backchannel = Backchannel;
 126        }
 5127        if (BackchannelHttpHandler != null)
 128        {
 0129            target.BackchannelHttpHandler = BackchannelHttpHandler;
 130        }
 5131        if (BackchannelTimeout != default)
 132        {
 5133            target.BackchannelTimeout = BackchannelTimeout;
 134        }
 135
 136        // Claim actions
 5137        if (ClaimActions != null)
 138        {
 14139            foreach (var jka in ClaimActions
 5140                .OfType<Microsoft.AspNetCore.Authentication.OAuth.Claims.JsonKeyClaimAction>()
 7141                .Where(a => !string.IsNullOrEmpty(a.JsonKey) && !string.IsNullOrEmpty(a.ClaimType)))
 142            {
 2143                target.ClaimActions.MapJsonKey(jka.ClaimType, jka.JsonKey);
 144            }
 145        }
 146
 147        // Events - copy if provided
 5148        if (Events != null)
 149        {
 5150            target.Events = Events;
 151        }
 5152        if (EventsType != null)
 153        {
 0154            target.EventsType = EventsType;
 155        }
 156
 157        // Other properties
 5158        target.StateDataFormat = StateDataFormat;
 5159    }
 160}