< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Authentication.BasicAuthenticationOptions
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Authentication/BasicAuthenticationOptions.cs
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 88
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_HeaderName()100%11100%
get_Base64Encoded()100%11100%
get_SeparatorRegex()100%11100%
get_Realm()100%11100%
get_Logger()100%11100%
get_RequireHttps()100%11100%
get_SuppressWwwAuthenticate()100%11100%
get_ValidateCredentialsAsync()100%11100%
get_ValidateCodeSettings()100%11100%
get_IssueClaims()100%11100%
get_IssueClaimsCodeSettings()100%11100%
get_ClaimPolicyConfig()100%11100%

File(s)

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

#LineLine coverage
 1using System.Security.Claims;
 2using System.Text.RegularExpressions;
 3using Microsoft.AspNetCore.Authentication;
 4using Kestrun.Claims;
 5
 6namespace Kestrun.Authentication;
 7
 8/// <summary>
 9/// Options for configuring Basic Authentication in Kestrun.
 10/// </summary>
 11public partial class BasicAuthenticationOptions : AuthenticationSchemeOptions, IAuthenticationCommonOptions
 12{
 13    /// <summary>
 14    /// Gets or sets the name of the HTTP header used for authentication.
 15    /// </summary>
 6416    public string HeaderName { get; set; } = "Authorization";
 17    /// <summary>
 18    /// Gets or sets a value indicating whether the credentials are Base64 encoded.
 19    /// </summary>
 6520    public bool Base64Encoded { get; set; } = true;
 21
 22    /// <summary>
 23    /// Gets or sets the regular expression used to separate the username and password in the credentials.
 24    /// </summary>
 5925    public Regex SeparatorRegex { get; set; } = MyRegex();
 26
 27
 28    /// <summary>
 29    /// Gets or sets the authentication realm used in the WWW-Authenticate header.
 30    /// </summary>
 3931    public string Realm { get; set; } = "Kestrun";
 32
 33    [GeneratedRegex("^([^:]*):(.*)$", RegexOptions.Compiled)]
 34    private static partial Regex MyRegex();
 35
 36    /// <summary>
 37    /// Gets or sets the Serilog logger used for authentication events.
 38    /// </summary>
 11839    public Serilog.ILogger Logger { get; set; } = Serilog.Log.ForContext<BasicAuthenticationOptions>();
 40
 41    /// <summary>
 42    /// Gets or sets a value indicating whether HTTPS is required for authentication.
 43    /// </summary>
 6544    public bool RequireHttps { get; set; } = true;
 45
 46    /// <summary>
 47    /// Gets or sets a value indicating whether to suppress the WWW-Authenticate header in responses.
 48    /// </summary>
 449    public bool SuppressWwwAuthenticate { get; set; }
 50
 51
 52    /// <summary>
 53    /// Delegate to validate user credentials.
 54    /// Parameters: HttpContext, username, password. Returns: Task&lt;bool&gt; indicating validity.
 55    /// </summary>
 7756    public Func<HttpContext, string, string, Task<bool>> ValidateCredentialsAsync { get; set; } = (_, _, _) => Task.From
 57
 58    /// <summary>
 59    /// Settings for the authentication code, if using a script.
 60    /// </summary>
 61    /// <remarks>
 62    /// This allows you to specify the language, code, and additional imports/refs.
 63    /// </remarks>
 4764    public AuthenticationCodeSettings ValidateCodeSettings { get; set; } = new();
 65
 66    /// <summary>
 67    /// After credentials are valid, this is called to add extra Claims.
 68    /// Parameters: HttpContext, username → IEnumerable of extra claims.
 69    /// </summary>
 1070    public Func<HttpContext, string, Task<IEnumerable<Claim>>>? IssueClaims { get; set; }
 71
 72    /// <summary>
 73    /// Settings for the claims issuing code, if using a script.
 74    /// </summary>
 75    /// <remarks>
 76    /// This allows you to specify the language, code, and additional imports/refs for claims issuance.
 77    /// </remarks>
 4778    public AuthenticationCodeSettings IssueClaimsCodeSettings { get; set; } = new();
 79
 80    /// <summary>
 81    /// Gets or sets the claim policy configuration.
 82    /// </summary>
 83    /// <remarks>
 84    /// This allows you to define multiple authorization policies based on claims.
 85    /// Each policy can specify a claim type and allowed values.
 86    /// </remarks>
 887    public ClaimPolicyConfig? ClaimPolicyConfig { get; set; }
 88}