'Is this how to get a refresh token using msal-node library?

I'm using the msal nodejs library. I have the following code

const ouathClient = new msal.ConfidentialClientApplication(msalConfig);

const tokenRequest = {
   code: request.query.code,
   scopes: process.env.OUTLOOK_OAUTH_SCOPES.split(','),
   redirectUri: process.env.DOMAIN_NAME + "/outlook/oauth/redirect",
   accessType: "offline"
};

const response = await ouathClient.acquireTokenByCode(tokenRequest);

const accessToken = response.accessToken;
const refreshToken = () => {
const tokenCache = ouathClient.getTokenCache().serialize();
const refreshTokenObject = (JSON.parse(tokenCache)).RefreshToken
const refreshToken = refreshTokenObject[Object.keys(refreshTokenObject)[0]].secret;
                return refreshToken;
            }
const tokens = {
   accessToken,
   refreshToken: refreshToken()
}

IS this how to get the refresh token from the msal-node library? I created an app that connects doctors and patients. I want patients to be able to book time on a doctor's outlook calendar. I need to get access to the doctor's outlook account. I can use the access token to get access to his calendar, but that expires.

How do I refresh the token after some time?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source