Graph Api Oauth2 Refresh Tokens Expiring

JoonaFinland 0 Reputation points
2023-10-24T08:55:41.8733333+00:00

I am running into problems with several users' refresh tokens becoming invalidated randomly. This can happen to users who have had their calendars connected for a long time, and also users who literally have just connected their calendar and the token is expired when trying to fetch events or subscribed to calendar notifications.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,774 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Carolyne-3676 201 Reputation points
    2023-11-15T16:52:13.1266667+00:00

    This issue can arise from several factors such as token revocation by the user, token expiration time, or token invalidation due to password reset or security events. Here are some possible steps you can take:

    1. Try and check the token expiration time and refresh tokens before making any Graph API requests. Ensure that the refresh token has not expired.
    2. You can try to implement a token refresh mechanism that automatically refreshes the access token when it is close to expiration. You can use the refresh_token grant type to obtain a new access token.
    3. If the user's password is reset or the user's account is deleted or disabled, the refresh token will become invalid. In this case, you will need to prompt the user to re-authenticate and grant permission again.

    You can use the Microsoft Graph API to retrieve the sign-in logs and audit logs. Relevant documentation can be found here Microsoft Graph API sign-in and audit logs

    0 comments No comments