Tokens
Extracting Access Token from Connect-MgGraph
# This is the method that actually grabs the byte array containing the token data.
$InMemoryTokenCacheGetTokenData = [Microsoft.Graph.PowerShell.Authentication.Core.TokenCache.InMemoryTokenCache].GetMethod("ReadTokenData",[System.Reflection.BindingFlags]::NonPublic+[System.Reflection.BindingFlags]::Instance)
# This is the raw JWT in a byte array.
$TokenData = $InMemoryTokenCacheGetTokenData.Invoke([Microsoft.Graph.PowerShell.Authentication.GraphSession]::Instance.InMemoryTokenCache,$null)
# Base64 encoding it (which is what most want...
[System.Convert]::ToBase64String($TokenData)
# Or as UTF8 string, if you want it that way.
[System.Text.Encoding]::UTF8.GetString($TokenData)
Secure Token
$secureAccessToken = $access_token | ConvertTo-SecureString -AsPlainText -Force
Last updated