< Summary

Information
Class: AsiBackbone.AspNetCore.Actors.AsiBackboneHttpActorContextOptions
Assembly: AsiBackbone.AspNetCore
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.AspNetCore/Actors/AsiBackboneHttpActorContextOptions.cs
Line coverage
100%
Covered lines: 29
Uncovered lines: 0
Coverable lines: 29
Total lines: 81
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_DefaultActorIdClaimTypes()100%11100%
.cctor()100%11100%
get_DefaultDisplayNameClaimTypes()100%11100%
get_ActorIdClaimTypes()100%11100%
get_DisplayNameClaimTypes()100%11100%
get_ActorTypeClaimType()100%11100%
get_DefaultAuthenticatedActorType()100%11100%
get_UnauthenticatedDisplayName()100%11100%
Validate()100%1010100%

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.AspNetCore/Actors/AsiBackboneHttpActorContextOptions.cs

#LineLine coverage
 1using System.Security.Claims;
 2using AsiBackbone.Core.Actors;
 3
 4namespace AsiBackbone.AspNetCore.Actors;
 5
 6/// <summary>
 7/// Configures how ASP.NET Core claims are mapped into framework-neutral actor contexts.
 8/// </summary>
 9public sealed class AsiBackboneHttpActorContextOptions
 10{
 11    /// <summary>
 12    /// Gets the default stable identifier claim types checked for authenticated actors.
 13    /// </summary>
 5314    public static IReadOnlyList<string> DefaultActorIdClaimTypes { get; } =
 315    [
 316        ClaimTypes.NameIdentifier,
 317        "sub",
 318        "oid",
 319        "client_id",
 320        "azp",
 321        ClaimTypes.Email,
 322    ];
 23
 24    /// <summary>
 25    /// Gets the default display-name claim types checked for authenticated actors.
 26    /// </summary>
 5327    public static IReadOnlyList<string> DefaultDisplayNameClaimTypes { get; } =
 328    [
 329        ClaimTypes.Name,
 330        "name",
 331        "preferred_username",
 332        ClaimTypes.Email,
 333        "email",
 334    ];
 35
 36    /// <summary>
 37    /// Gets or sets the claim types used to resolve a stable actor identifier.
 38    /// </summary>
 26339    public IList<string> ActorIdClaimTypes { get; set; } = [.. DefaultActorIdClaimTypes];
 40
 41    /// <summary>
 42    /// Gets or sets the claim types used to resolve an optional actor display name.
 43    /// </summary>
 13144    public IList<string> DisplayNameClaimTypes { get; set; } = [.. DefaultDisplayNameClaimTypes];
 45
 46    /// <summary>
 47    /// Gets or sets the claim type used to resolve an actor type.
 48    /// </summary>
 13149    public string ActorTypeClaimType { get; set; } = "actor_type";
 50
 51    /// <summary>
 52    /// Gets or sets the actor type used when an authenticated principal does not provide a valid actor type claim.
 53    /// </summary>
 6154    public AsiBackboneActorType DefaultAuthenticatedActorType { get; set; } = AsiBackboneActorType.Human;
 55
 56    /// <summary>
 57    /// Gets or sets the display name used for unauthenticated actors.
 58    /// </summary>
 1759    public string? UnauthenticatedDisplayName { get; set; }
 60
 61    /// <summary>
 62    /// Validates the options.
 63    /// </summary>
 64    public void Validate()
 65    {
 6266        if (ActorIdClaimTypes is null || ActorIdClaimTypes.Count == 0 || ActorIdClaimTypes.All(string.IsNullOrWhiteSpace
 67        {
 868            throw new InvalidOperationException("At least one actor identifier claim type must be configured.");
 69        }
 70
 5471        if (DisplayNameClaimTypes is null)
 72        {
 273            throw new InvalidOperationException("DisplayNameClaimTypes must be configured.");
 74        }
 75
 5276        if (string.IsNullOrWhiteSpace(ActorTypeClaimType))
 77        {
 678            throw new InvalidOperationException("ActorTypeClaimType must be configured.");
 79        }
 4680    }
 81}