Show-JWTtoken.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
function Show-JWTtoken { [CmdletBinding()] Param( [Parameter(Mandatory=$true)] [String]$Token ) if (!$token.Contains(".") -or !$token.StartsWith("eyJ")) { Write-Error "Invalid token" -ErrorAction Stop } $TokenParts = $Token.Replace('-', '+').Replace('_', '/').Split(".") #Header While ($TokenParts[0].Length % 4) { $TokenParts[0] += "=" } $TokenHeader = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($TokenParts[0])) | ConvertFrom-Json #Payload While ($TokenParts[1].Length % 4) { $TokenParts[1] += "=" } $TokenPayload = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($TokenParts[1])) | ConvertFrom-Json #Signature While ($TokenParts[2].Length % 4) { $TokenParts[2] += "=" } $TokenSignature = $TokenParts[2] $DecodedToken = New-Object -Type PSObject -Property @{ Header = $TokenHeader Payload = $TokenPayload Signature = $TokenSignature } $DecodedTokenJson = $DecodedToken | ConvertTo-Json Return $DecodedTokenJson } |