MS Graph react SPA get refresh token

Navdeep Singh 1 Reputation point
2022-01-09T09:16:46.647+00:00

I am using msgraph-training-reactspa sdk from Microsoft which uses MSAL for authentication. It does not return any refresh token. It has acquireTokenSilent method which gets new access token.

As per our requirement I want to get user access token along with refresh token so that I can later get new access token with refresh token and use microsoft graph api in CRON to update data.

How can we login user to microsoft via react app and get the refresh token so that I can save it in my DB?

Can I get any sample reference?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,889 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,456 questions
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 41,291 Reputation points
    2022-01-11T10:12:21.887+00:00

    Hi @Navdeep Singh

    You just need to add offline_access in scope, after that you will get refresh token.

    scope = "https://graph.microsoft.com/.default offline_access"  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.