| | 1 | | <# |
| | 2 | | .SYNOPSIS |
| | 3 | | Validates a JWT token against the builder's parameters. |
| | 4 | | .DESCRIPTION |
| | 5 | | This function validates a JWT token against the parameters set in the JWT builder, checking for expiration, issu |
| | 6 | | .PARAMETER Result |
| | 7 | | The JWT builder result containing the token and validation parameters. |
| | 8 | | .PARAMETER Token |
| | 9 | | The JWT token to validate. |
| | 10 | | .PARAMETER ClockSkew |
| | 11 | | The allowed clock skew for validation, defaulting to 1 minute. |
| | 12 | | .OUTPUTS |
| | 13 | | [bool] |
| | 14 | | Returns true if the token is valid, otherwise false. |
| | 15 | | .EXAMPLE |
| | 16 | | $isValid = New-KrJWTTokenBuilder | Add-KrJWTSubject -Subject "mySubject" | Build-KrJWT | Test-KrJWT -Token $toke |
| | 17 | | This example creates a new JWT token builder, adds a subject, and then tests the validity of the JWT token. |
| | 18 | | .NOTES |
| | 19 | | This function is part of the Kestrun.Jwt module and is used to validate JWT tokens. |
| | 20 | | Maps to JwtBuilderResult.Validate |
| | 21 | | .LINK |
| | 22 | | https://docs.microsoft.com/en-us/dotnet/api/system.identitymodel.tokens.jwt.jwtsecuritytoken |
| | 23 | | #> |
| | 24 | | function Test-KrJWT { |
| | 25 | | [KestrunRuntimeApi('Everywhere')] |
| | 26 | | [CmdletBinding()] |
| | 27 | | [OutputType([bool])] |
| | 28 | | param( |
| | 29 | | [Parameter(Mandatory = $true, ValueFromPipeline)] |
| | 30 | | [Kestrun.Jwt.JwtBuilderResult] $Result, |
| | 31 | | [Parameter(Mandatory)] |
| | 32 | | [string] $Token, |
| | 33 | | [Parameter()] |
| 0 | 34 | | [TimeSpan] $ClockSkew = ([TimeSpan]::FromMinutes(1)) |
| | 35 | | ) |
| | 36 | | process { |
| 0 | 37 | | $validationResult = $Result.Validate($Token, $ClockSkew) |
| 0 | 38 | | return $validationResult.IsValid |
| | 39 | | } |
| | 40 | | } |
| | 41 | |
|