Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating an imported access token doesn't work in PowerShell 7 #41

Open
ghvanderweg opened this issue Mar 5, 2020 · 0 comments
Open

Comments

@ghvanderweg
Copy link

ghvanderweg commented Mar 5, 2020

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant