401 Unauthorized When accessing calendar events

Marc 45 Reputation points
2025-05-04T09:08:01.8466667+00:00

Hello,

I use the Microsoft oauth system with the @azure/msal-node librabry. Everything seem to work on the auth side, and Im even capable of reading user data from the endpoint GET /me using the access token.

However, when im trying to access the calendar events, i get a 401 Unauthorized error without any more details to guide me. I've spent 8 hours trying everything I've found online, but didnt help.

My system should work this way:
1- the user accept my app and give me user and calendar access

2- later on the backend side (nodejs) i can get and create events in his calendar when needed

Here you can see the App permissions:User's image

And some code:

User's image User's image

working request:

User's image

Not working (401 error):
User's image

I also tried to get the access token this way:
User's image

But i get the same error...

Please help, I have probably missed something 🙏

Microsoft Security | Microsoft Entra | Microsoft Entra ID

Answer accepted by question author
Sridevi Machavarapu 5,885 Reputation points Volunteer Moderator
2025-05-13T08:37:16.8966667+00:00

Hello Marc,

I understand you're using the @azure/msal-node library to access calendar events with a personal Microsoft account. While the /me endpoint works, you're seeing a 401 error when trying to call /me/events.

This usually happens because personal Microsoft accounts like @outlook.com or @hotmail.com don't support application permissions. They only support delegated permissions, which require the user to sign in at least once and approve the needed scopes.

Here are a few things to check:

  • Make sure your app registration supports personal Microsoft accounts. In the Azure portal, select correct supported account type.
  • Use /common in the authority URL instead of a specific tenant ID to ensure compatibility with personal accounts.
  • Include offline_access and Calendars.ReadWrite in your scope list. This allows your app to get a refresh token so you can later acquire access tokens silently.

Application permissions are designed for background apps that run without a signed-in user. These only work with work or school accounts, like emails ending in @companyname.onmicrosoft.com. With Application permissions, your app can manage events in other users' calendars without needing them to sign in. This does not apply to personal Microsoft accounts.

Below is a sample Node.js app that uses delegated permissions for personal Microsoft accounts. It lets a user sign in, creates a calendar event, lists existing events, and uses the refresh token to acquire new access tokens silently.

index.js

After running the app, sign in with a personal Microsoft account when prompted.

User's image

Once signed in, the event is created, and calendar events are listed.

User's image

Output:

User's image

Let me know if you have any further queries. Happy to assist.

Hope this helps!


If this answers your query, do click Accept Answer and Yes for was this answer helpful, which may help members with similar questions.

User's image

If you have any other questions or are still experiencing issues, feel free to ask in the "comments" section, and I'd be happy to help.

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

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