Skip to content

Instantly share code, notes, and snippets.

@azurekid
Created December 19, 2022 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azurekid/16983a65bdc31ea407780a5bfeedbe40 to your computer and use it in GitHub Desktop.
Save azurekid/16983a65bdc31ea407780a5bfeedbe40 to your computer and use it in GitHub Desktop.
function Invoke-SplitJWT {
Param
(
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
Position = 0)]
$String
)
Process {
$Length = $String.Length
if ($String.Length % 4 -ne 0) {
$Length += 4 - ($String.Length % 4)
}
return $String.PadRight($Length, "=")
}
}
function ConvertFrom-JWT {
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
Position = 0)]
$Base64JWT
)
Begin {
}
Process {
$Spl = $Base64JWT.Split(".")
[PSCustomObject] @{
Header = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String((Invoke-SplitJWT $Spl[0]))) | ConvertFrom-Json
Payload = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String((Invoke-SplitJWT $Spl[1]))) | ConvertFrom-Json
}
}
End {
}
}
@azurekid
Copy link
Author

Example

( ConvertFrom-JWT -Base64JWT "<the graph token>" ).payload

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment