You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While writing this I kept digging deeper to find a solution, and I think I've got it, so I'd like to explain my thought process :)
I upgraded to PowerShell 7 today, and Update-GraphOauthAccessToken broke. After using Export-GraphOauthAccessToken and Import-GraphOauthAccessToken to export & import an access token, if you then try to update the token with Update-GraphOauthAccessToken, it fails with the error:
Update-GraphOauthAccessToken: Failed to refresh token: The format of value '' is invalid.
In PowerShell 5.1, this works fine.
I tracked the error down to the WebSession header in the Invoke-Webrequest call (line 102 of Update-GraphOauthAccessToken.ps1). Omitting that header fixed the issue. But since the header works fine in PowerShell 5.1, I looked into it a bit further.
I compared the Session property of an original access token and an imported token, and it seems the Session property loses the content of the UserAgent subproperty on serializing/deserializing.
Manually adding the user agent back fixed the issue. Next, I checked the XML that's saved to disk, and the user agent is present there, so the issue has to be with Import-GraphOauthAccessToken.ps1. I think I located a bug at line 110, which reads
$Session.UserAgent = $Application.UserAgent
If I'm not mistaken, this should be
$Session.UserAgent = $InObject.Session.UserAgent
This will properly deserialize the UserAgent property and keep Invoke-WebRequest happy :)
The text was updated successfully, but these errors were encountered:
While writing this I kept digging deeper to find a solution, and I think I've got it, so I'd like to explain my thought process :)
I upgraded to PowerShell 7 today, and
Update-GraphOauthAccessToken
broke. After usingExport-GraphOauthAccessToken
andImport-GraphOauthAccessToken
to export & import an access token, if you then try to update the token withUpdate-GraphOauthAccessToken
, it fails with the error:Update-GraphOauthAccessToken: Failed to refresh token: The format of value '' is invalid.
In PowerShell 5.1, this works fine.
I tracked the error down to the
WebSession
header in theInvoke-Webrequest
call (line 102 ofUpdate-GraphOauthAccessToken.ps1
). Omitting that header fixed the issue. But since the header works fine in PowerShell 5.1, I looked into it a bit further.I compared the Session property of an original access token and an imported token, and it seems the Session property loses the content of the UserAgent subproperty on serializing/deserializing.
Manually adding the user agent back fixed the issue. Next, I checked the XML that's saved to disk, and the user agent is present there, so the issue has to be with
Import-GraphOauthAccessToken.ps1
. I think I located a bug at line 110, which reads$Session.UserAgent = $Application.UserAgent
If I'm not mistaken, this should be
$Session.UserAgent = $InObject.Session.UserAgent
This will properly deserialize the UserAgent property and keep Invoke-WebRequest happy :)
The text was updated successfully, but these errors were encountered: