markekraus / PSMSGraph

A PowerShell module for the Microsoft Graph API
MIT License
82 stars 21 forks source link

Token Expired when Obtained #36

Closed ReArmedHalo closed 5 years ago

ReArmedHalo commented 5 years ago

Similar to #31, I am running into the this problem suddenly

PSMSGraph Version: 1.0.26.43

Relevant code: https://github.com/ReArmedHalo/DUST/blob/develop/DUST/public/Microsoft%20365%20Health%20Check%20Reports/Invoke-Microsoft365HealthCheck.ps1

Building the application in Azure AD: https://github.com/ReArmedHalo/DUST/blob/develop/DUST/private/Microsoft%20365%20Health%20Check/Support/New-DUSTAzureADApiApplication.ps1

Using PSMSGraph to get consent for permissions and an access token: https://github.com/ReArmedHalo/DUST/blob/develop/DUST/private/Microsoft%20365%20Health%20Check/Support/Get-DUSTAzureADApiApplicationConsent.ps1

VERBOSE: Retrieving OAuth Access Token from https://login.microsoftonline.com/common/oauth2/token... VERBOSE: POST https://login.microsoftonline.com/common/oauth2/token with -1-byte payload VERBOSE: received 4142-byte response of content type application/json; charset=utf-8 VERBOSE: Access Token: Guid: <blah> IsExpired 'True'

Everything was working fine about two weeks ago. I then came back in and tried to test a new report I was trying to grab and determined I could no longer get a valid token. I don't remember what that error was but I went through a few iteration of trying other code and ended up back here after a week of troubleshooting.

markekraus commented 5 years ago

This si the same bug as all the others. It has to due with the way the expiry time is calculated and differences in UTC and local times. This has already been fixed but not yet released.

ReArmedHalo commented 5 years ago

Thanks @markekraus, I wasn't sure if this was entirely related. Do you happen to have an ETA to when it will be released? I'm manually working around this by popping up a browser window and making REST calls to the token endpoint. It's not very pretty :)

markekraus commented 5 years ago

new version released that should fix this https://www.powershellgallery.com/packages/psmsgraph/1.0.27.60