TLDR: Refreshing token works for outlook account's, but I get error AADSTS65001 when I try to refresh the token of a work account.
I am building a scheduling app (nodejs/react) where my users can integrate their outlook calendars so visitors can schedule events in their calendars. I am using @azure/msal-node for authentication.
Msal config
const msalConfig = {
auth: {
clientId: MICROSOFT_CREDENTIALS.CLIENT_ID,
authority: 'https://login.microsoftonline.com/common/',
clientSecret: MICROSOFT_CREDENTIALS.CLIENT_SECRET
}
};
Msal.ConfidentialClientApplication(msalConfig);
My app registration info:
Supported account types: All Microsoft account users
Api permissions (all Delegated): Calendars.ReadWrite, offline_access, User.Read
My app flow looks like this:
- User has in his profile a button to authenticate, gets redirected to url generated with msalClient.getAuthCodeUrl where he is asked for permissions,
- After consenting, he gets redirected back with a code which I use to get the access token (msalClient.acquireTokenByCode),
- I test I have access by calling '/me' endpoint and displaying account display name,
- I get refresh token from msal token cache (getTokenCache().serialize() and get the right one with homeAccountId) and map it to the user,
- Now that user has integrated outlook calendar, visitor should be able to schedule an event with him,
- Visitor fills out event data,
- Before creating the event, I get an access token by posting users refresh token to 'https://login.microsoftonline.com/common/oauth2/v2.0/token' using the grant_type: 'refresh_token',
- I post the event data to 'me/calendar/events' with the new access token.
This works perfectly with outlook.com accounts, but when I try it with a work account .onmicrosoft.com I get an error on step 7, when I try to refresh the token.. the error is:
AADSTS65001: The user or administrator has not consented to use the application with ID '[app id]' named '[app name]'. Send an interactive authorization request for this user and resource.
I hope someone can help with this, I will gladly provide more information if needed!