This article provides solutions to the error "IDX14102: Unable to decode the header" that occurs when you use Microsoft Graph PowerShell.
Symptoms
When running the Microsoft Graph PowerShell command Connect-MgGraph -AccessToken $token, you receive the following error:
IDX14102: Unable to decode the header
Cause
This error occurs because an invalid access token is passed to the AccessToken parameter of the Connect-MgGraph cmdlet. This problem often occurs when the token is obtained via Azure PowerShell's Get-AzAccessToken cmdlet and passed as a SecureString. This behavior is observed starting with version 5.0.0 of the Az.Accounts module. Starting from Microsoft Graph PowerShell version 2.28.0, the Connect-MgGraph command accepts only a plain string as the AccessToken parameter.
Solution
Here are two solutions for resolving this issue:
-
Make sure the access token passed to the
AccessTokenparameter of theConnect-MgGraphcmdlet is valid.For more information about access tokens, see Access tokens in the Microsoft identity platform.
-
If you use the
Get-AzAccessTokencmdlet to obtain the access token, use one of the following methods:-
Downgrade
Az.Accountsto version 4.2.0 to avoid the token being returned as aSecureString. -
Convert the token from
SecureStringtoString:$microsoftGraphToken = Get-AzAccessToken -ResourceUrl "https://graph.microsoft.com" Connect-MgGraph -AccessToken (ConvertFrom-SecureString -SecureString $microsoftGraphToken.Token -AsPlainText)
-
Source: Microsoft Learn / IT Pro troubleshooting by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.
