private/get-JwtTokenProperties.ps1
function Get-JwtTokenProperties { <# Author = "Jos Lieben (jos@lieben.nu)" CompanyName = "Lieben Consultancy" Copyright = "https://www.lieben.nu/liebensraum/commercial-use/" #> param( [Parameter(Mandatory=$true)][string]$token ) if (!$token.Contains(".") -or !$token.StartsWith("eyJ")) { Write-Error "Invalid token" -ErrorAction Stop } $tokenheader = $token.Split(".")[0].Replace('-', '+').Replace('_', '/') while ($tokenheader.Length % 4) {$tokenheader += "=" } $tokenPayload = $token.Split(".")[1].Replace('-', '+').Replace('_', '/') while ($tokenPayload.Length % 4) {$tokenPayload += "=" } $tokenByteArray = [System.Convert]::FromBase64String($tokenPayload) $tokenArray = [System.Text.Encoding]::ASCII.GetString($tokenByteArray) $tokobj = $tokenArray | ConvertFrom-Json return $tokobj } |