Token expires

Jair Bakhuis 1 Reputation point
2021-01-23T09:58:04.373+00:00

Hi,
I have a question about this tutorial: https://learn.microsoft.com/en-us/graph/tutorials/node?view=graph-rest-1.0

Everything is successfully implemented, I can log in and get the calendar view, also I change to get the emails, it works well.
The only problem is that the Token only works for a few hours. After that time we need to re-login again to get the emails.

Is this a known issue and how can I solve it?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,431 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Deva-MSFT 2,256 Reputation points Microsoft Employee
    2021-01-27T19:08:27.647+00:00

    I remember the sample - so your application has an access token, which is sent in the Authorization header of API calls. This is the token that allows the app to access the Microsoft Graph on the user's behalf. However, this token is short-lived. The token expires an hour after it is issued. This is where the refresh token becomes useful. The OAuth specification introduces a refresh token, which allows the app to request a new access token without requiring the user to sign in again.

    Also the above sample app is using the msal-node package - so you do not need to implement any token storage or refresh logic. The app uses the default msal-node in-memory token cache, which is sufficient for the sample application. Production applications should provide their own caching plugin to serialize the token cache in a secure, reliable storage medium.

    0 comments No comments