< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Authentication.AuthenticationBuilderExtensions
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Authentication/AuthenticationBuilderExtension.cs
Tag: Kestrun/Kestrun@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
0%
Covered lines: 0
Uncovered lines: 24
Coverable lines: 24
Total lines: 54
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
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: 0% (0/24) Branch coverage: 0% (0/2) Total lines: 54 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd 12/12/2025 - 17:27:19 Line coverage: 0% (0/24) Branch coverage: 0% (0/2) Total lines: 54 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddCookie(...)0%620%

File(s)

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

#LineLine coverage
 1
 2using Microsoft.AspNetCore.Authentication;
 3using Microsoft.AspNetCore.Authentication.Cookies;
 4using Microsoft.Extensions.DependencyInjection.Extensions;
 5using Microsoft.Extensions.Options;
 6
 7namespace Kestrun.Authentication;
 8
 9/// <summary>
 10/// Extension methods for <see cref="AuthenticationBuilder"/> to add cookie authentication.
 11/// </summary>
 12internal static class AuthenticationBuilderExtensions
 13{
 14    /// <summary>
 15    /// Adds cookie authentication to <see cref="AuthenticationBuilder"/> using the specified scheme.
 16    /// <para>
 17    /// Cookie authentication uses a HTTP cookie persisted in the client to perform authentication.
 18    /// </para>
 19    /// </summary>
 20    /// <param name="builder">The <see cref="AuthenticationBuilder"/>.</param>
 21    /// <param name="authenticationScheme">The authentication scheme.</param>
 22    /// <param name="displayName">A display name for the authentication handler.</param>
 23    /// <param name="configureOptions">A delegate to configure <see cref="CookieAuthenticationOptions"/>.</param>
 24    /// <returns>A reference to <paramref name="builder"/> after the operation has completed.</returns>
 25    public static AuthenticationBuilder AddCookie(this AuthenticationBuilder builder, string authenticationScheme, strin
 26    {
 027        builder.Services.TryAddEnumerable(
 028            ServiceDescriptor.Singleton<
 029                IPostConfigureOptions<CookieAuthenticationOptions>,
 030                PostConfigureCookieAuthenticationOptions>());
 31
 032        _ = builder.Services
 033            .AddOptions<CookieAuthenticationOptions>(authenticationScheme)
 034            .Validate(o => o.Cookie.Expiration == null,
 035                "Cookie.Expiration is ignored, use ExpireTimeSpan instead.");
 36
 037        return builder.AddScheme<CookieAuthenticationOptions, CookieAuthenticationHandler>(authenticationScheme, display
 038            {
 039                if (configureOptions is null)
 040                {
 041                    return;
 042                }
 043
 044                // Start from a fresh Kestrun-friendly options object
 045                var userOptions = new CookieAuthOptions();
 046
 047                // Let the caller configure all the rich stuff
 048                configureOptions(userOptions);
 049
 050                // Push everything into the real framework options
 051                userOptions.ApplyTo(options);
 052            });
 53    }
 54}