401 InvalidAuthenticationToken: Access token has expired or is not yet valid.

Sajed Almorsy 10 Reputation points
2023-05-23T22:56:19.4+00:00

We are using Microsoft Graph API to send Outlook emails.

The access token expires after ~1 hour, we refresh it with the refresh token and it works just fine.

However, sometimes, the access token is refreshed successfully, we see the new expiration date which is 1 hour in the future, but trying to use the newly obtained access token we get the following error:

401 InvalidAuthenticationToken: Access token has expired or is not yet valid. from 

This doesn't happen every time we refresh the token, sometimes it works well for several months and then we get the above error.

the error says has expired or is not yet valid, it's not expired because the expiration date is 1 hour in the future by the time we see the error as it's just refreshed.

so we think it might be or is not yet valid, do we have to wait for some time before we start using the new access token, Any other suggestions?

Microsoft Authenticator
Microsoft Authenticator
A Microsoft app for iOS and Android devices that enables authentication with two-factor verification, phone sign-in, and code generation.
5,487 questions
Outlook
Outlook
A family of Microsoft email and calendar products.
2,955 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,581 questions
{count} vote