unable to see offline_access Scope Missing from Token Response
I’m using MSAL.js in my Outlook Add-in to authenticate users and obtain tokens. My configuration includes the offline_access scope, but it appears to be missing from the token response. This prevents me from getting a refresh token. Here is my current configuration and token request code:
const msalConfig = {
auth: {
clientId: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
authority: "https://login.microsoftonline.com/common",
redirectUri: _redirectUri,
},
cache: {
cacheLocation: "localStorage", // This configures where your cache will be stored
storeAuthStateInCookie: true, // Set this to "true" if you are having issues on IE11 or Edge
},
system: {
loggerOptions: {
loggerCallback: (level, message, containsPii) => {
if (containsPii) {
return;
}
switch (level) {
case msal.LogLevel.Error:
console.error(message);
return;
case msal.LogLevel.Info:
console.info(message);
return;
case msal.LogLevel.Verbose:
console.debug(message);
return;
case msal.LogLevel.Warning:
console.warn(message);
return;
}
},
},
},
};
const loginRequest = {
scopes: ["User.Read", "Mail.ReadWrite", "offline_access"],
prompt: "select_account",
};
const tokenRequest = {
scopes: ["User.Read", "Mail.ReadWrite", "offline_access"],
prompt: "select_account",
forceRefresh: true,
};
function getTokenPopup(request, myMSALObj, username) {
request.account = myMSALObj.getAccountByUsername(username);
return myMSALObj.acquireTokenSilent(request).catch((error) => {
console.warn("Silent token acquisition fails. Acquiring token using popup");
if (error instanceof msal.InteractionRequiredAuthError) {
return myMSALObj.acquireTokenPopup(request)
.then((tokenResponse) => {
// Log the token response to see what's included
console.log("Popup token acquisition successful:", tokenResponse);
// Check if tokenResponse includes the necessary tokens
const { accessToken, idToken, expiresOn, scopes, account } = tokenResponse;
console.log("Access Token:", accessToken);
console.log("ID Token:", idToken);
console.log("Expires On:", expiresOn);
console.log("Scopes:", scopes);
console.log("Account:", account);
// Check if offline_access scope is included
if (scopes.includes("offline_access")) {
console.log("Refresh token should be available.");
} else {
console.log("Refresh token is not available. Ensure offline_access scope is requested.");
}
// Return the token response for further processing
return tokenResponse;
})
.catch((error) => {
console.error("Popup token acquisition failed:", error);
});
} else {
console.warn("Non-interaction error occurred:", error);
}
});
}
I have set the permission on Azure AD as well.