| | 1 | | <# |
| | 2 | | .SYNOPSIS |
| | 3 | | Retrieves the validation parameters for a JWT token builder result. |
| | 4 | | .DESCRIPTION |
| | 5 | | This function extracts the validation parameters from a JWT builder result, which can be used for validating JWT |
| | 6 | | .PARAMETER Result |
| | 7 | | The JWT builder result containing the token to validate. |
| | 8 | | .PARAMETER ClockSkew |
| | 9 | | The allowed clock skew for validation, defaulting to 1 minute. |
| | 10 | | .OUTPUTS |
| | 11 | | [System.IdentityModel.Tokens.Jwt.TokenValidationParameters] |
| | 12 | | The validation parameters extracted from the JWT builder result. |
| | 13 | | .EXAMPLE |
| | 14 | | $validationParams = Get-KrJWTValidationParameter -Result $tokenBuilderResult -ClockSkew (New-TimeSpan -Minutes 5 |
| | 15 | | This example retrieves the validation parameters from the specified JWT builder result with a clock skew of 5 mi |
| | 16 | | .EXAMPLE |
| | 17 | | $JwtKeyHex = "6f1a1ce2e8cc4a5685ad0e1d1f0b8c092b6dce4f7a08b1c2d3e4f5a6b7c8d9e0"; |
| | 18 | | $JwtTokenBuilder = New-KrJWTBuilder | |
| | 19 | | Add-KrJWTIssuer -Issuer $issuer | |
| | 20 | | Add-KrJWTAudience -Audience $audience | |
| | 21 | | Protect-KrJWT -HexadecimalKey $JwtKeyHex -Algorithm HS256 |
| | 22 | |
|
| | 23 | | # Add a JWT bearer authentication scheme using the validation parameters |
| | 24 | | Add-KrJWTBearerAuthentication -Name "JwtScheme" -Options (Build-KrJWT -Builder $JwtTokenBuilder | Get-KrJWTValid |
| | 25 | | This example creates a JWT token builder, adds an issuer and audience, protects the JWT with a hexadecimal key, |
| | 26 | | .NOTES |
| | 27 | | This function is part of the Kestrun.Jwt module and is used to manage JWT tokens. |
| | 28 | | Maps to JwtBuilderResult.GetValidationParameters |
| | 29 | | .LINK |
| | 30 | | https://docs.microsoft.com/en-us/dotnet/api/system.identitymodel.tokens.jwt.jwtsecuritytoken |
| | 31 | | #> |
| | 32 | | function Get-KrJWTValidationParameter { |
| | 33 | | [KestrunRuntimeApi('Everywhere')] |
| | 34 | | [CmdletBinding()] |
| | 35 | | [OutputType([bool])] |
| | 36 | | param( |
| | 37 | | [Parameter(Mandatory = $true, ValueFromPipeline)] |
| | 38 | | [Kestrun.Jwt.JwtBuilderResult] $Result, |
| | 39 | | [Parameter()] |
| 1 | 40 | | [TimeSpan] $ClockSkew = ([TimeSpan]::FromMinutes(1)) |
| | 41 | | ) |
| | 42 | | process { |
| 1 | 43 | | return $Result.GetValidationParameters($ClockSkew) |
| | 44 | | } |
| | 45 | | } |
| | 46 | |
|