< Summary - Kestrun — Combined Coverage

Information
Class: Public.JWT.Add-KrJWTClaim
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/JWT/Add-KrJWTClaim.ps1
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
0%
Covered lines: 0
Uncovered lines: 3
Coverable lines: 3
Total lines: 51
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

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/JWT/Add-KrJWTClaim.ps1

#LineLine coverage
 1
 2<#
 3    .SYNOPSIS
 4        Adds a claim to the JWT token builder.
 5    .DESCRIPTION
 6        This function adds a claim to the JWT token builder, allowing for the specification of additional data.
 7    .PARAMETER Builder
 8        The JWT token builder to modify.
 9    .PARAMETER ClaimType
 10        The type of the claim to add.
 11    .PARAMETER UserClaimType
 12        The user-specific type of the claim to add, such as "Admin", "User", etc.
 13        This parameter is used when the claim type is based on user identity claims.
 14    .PARAMETER Value
 15        The value of the claim to add.
 16    .OUTPUTS
 17        [Kestrun.Jwt.JwtTokenBuilder]
 18        The modified JWT token builder.
 19    .EXAMPLE
 20        $builder = New-KrJWTTokenBuilder | Add-KrJWTClaim -Type "role" -Value "admin"
 21        This example creates a new JWT token builder and adds a claim to it.
 22    .NOTES
 23        This function is part of the Kestrun.Jwt module and is used to build JWT tokens
 24        Maps to JwtTokenBuilder.AddClaim
 25    .LINK
 26        https://docs.microsoft.com/en-us/dotnet/api/system.identitymodel.tokens.jwt.jwtsecuritytoken
 27#>
 28function Add-KrJWTClaim {
 29    [KestrunRuntimeApi('Everywhere')]
 30    [CmdletBinding(DefaultParameterSetName = 'ClaimType')]
 31    [OutputType([Kestrun.Jwt.JwtTokenBuilder])]
 32    param(
 33        [Parameter(Mandatory = $true, ValueFromPipeline)]
 34        [Kestrun.Jwt.JwtTokenBuilder] $Builder,
 35        [Parameter(Mandatory = $true, ParameterSetName = 'ClaimType')]
 36        [string] $ClaimType,
 37        [Parameter(Mandatory = $true, ParameterSetName = 'UserClaimType')]
 38        [Kestrun.Claims.UserIdentityClaim] $UserClaimType,
 39        [Parameter(Mandatory = $true)]
 40        [string] $Value
 41    )
 42    process {
 43        # resolve ClaimType if the user chose the enum parameter-set
 044        if ($UserClaimType) {
 045            $ClaimType = [Kestrun.Claims.KestrunClaimExtensions]::ToClaimUri($UserClaimType)
 46        }
 47
 048        return $Builder.AddClaim($ClaimType, $Value)
 49    }
 50}
 51

Methods/Properties

Add-KrJWTClaim()