< Summary - Kestrun — Combined Coverage

Information
Class: Public.ClaimPolicy.Add-KrClaimPolicy
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/ClaimPolicy/Add-KrClaimPolicy.ps1
Tag: Kestrun/Kestrun@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
0%
Covered lines: 0
Uncovered lines: 6
Coverable lines: 6
Total lines: 71
Line coverage: 0%
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 08/26/2025 - 14:53:17 Line coverage: 100% (3/3) Total lines: 46 Tag: Kestrun/Kestrun@78d1e497d8ba989d121b57aa39aa3c6b22de743109/04/2025 - 22:37:32 Line coverage: 100% (3/3) Total lines: 47 Tag: Kestrun/Kestrun@afb7aadc0a8a42bfa2b51ea62c8a6e2cf63faec610/13/2025 - 16:52:37 Line coverage: 0% (0/3) Total lines: 47 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e12/12/2025 - 17:27:19 Line coverage: 0% (0/6) Total lines: 71 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/ClaimPolicy/Add-KrClaimPolicy.ps1

#LineLine coverage
 1<#
 2.SYNOPSIS
 3    Adds a new claim policy to the KestrunClaims system.
 4.DESCRIPTION
 5    This function allows you to define a new claim policy by specifying the policy name, claim type, and allowed values.
 6.PARAMETER Builder
 7    The claim policy builder instance used to create the policy.
 8.PARAMETER PolicyName
 9    The name of the policy to be created.
 10.PARAMETER ClaimType
 11    The type of claim being defined.
 12.PARAMETER Scope
 13    If specified, indicates that the claim type is a scope.
 14.PARAMETER Description
 15    The description of the claim policy.
 16.PARAMETER UserClaimType
 17    The user identity claim type.
 18.PARAMETER AllowedValues
 19    The values that are allowed for this claim.
 20.EXAMPLE
 21    PS C:\> Add-KrClaimPolicy -Builder $builder -PolicyName "ExamplePolicy" -ClaimType "ExampleClaim" -AllowedValues "Va
 22    This is an example of how to use the Add-KrClaimPolicy function.
 23    It creates a claim policy named "ExamplePolicy" for the claim type "ExampleClaim" with allowed values "Value1" and "
 24.EXAMPLE
 25    PS C:\> Add-KrClaimPolicy -Builder $builder -PolicyName "ScopePolicy" -Scope -AllowedValues "read", "write"
 26    This example creates a claim policy named "ScopePolicy" for the claim type "scope" with allowed values "read" and "w
 27.NOTES
 28    This function is part of the Kestrun.Jwt module and is used to build Claims
 29#>
 30function Add-KrClaimPolicy {
 31    [KestrunRuntimeApi('Everywhere')]
 32    [CmdletBinding(DefaultParameterSetName = 'ClaimType')]
 33    [OutputType([Kestrun.Claims.ClaimPolicyBuilder])]
 34    param(
 35        [Parameter(Mandatory = $true, ValueFromPipeline)]
 36        [Kestrun.Claims.ClaimPolicyBuilder] $Builder,
 37
 38        [Parameter(Mandatory = $true)]
 39        [string] $PolicyName,
 40
 41        [Parameter(Mandatory = $true, ParameterSetName = 'ClaimType')]
 42        [string] $ClaimType,
 43
 44        [Parameter(Mandatory = $true, ParameterSetName = 'UserClaimType')]
 45        [Kestrun.Claims.UserIdentityClaim] $UserClaimType,
 46
 47        [Parameter(Mandatory = $true, ParameterSetName = 'Scope')]
 48        [switch]$Scope,
 49
 50        [Parameter(Mandatory = $true, ParameterSetName = 'ClaimType')]
 51        [Parameter(Mandatory = $true, ParameterSetName = 'UserClaimType')]
 52        [string[]] $AllowedValues,
 53
 54        [Parameter(Mandatory = $false)]
 55        [string]$Description
 56    )
 57    begin {
 58        # Determine claim type based on parameter set
 059        if ($Scope) {
 060            $ClaimType = 'scope'
 061            $AllowedValues = @($PolicyName)
 062        } elseif ($UserClaimType) {
 63            # Use user identity claim type
 064            $ClaimType = [Kestrun.Claims.KestrunClaimExtensions]::ToClaimUri($UserClaimType)
 65        }
 66    }
 67    process {
 068        return $Builder.AddPolicy($PolicyName, $ClaimType, $Description, $AllowedValues)
 69    }
 70}
 71

Methods/Properties

Add-KrClaimPolicy()