A cloud-based identity and access management service for securing user authentication and resource access
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
/commonin the authority URL instead of a specific tenant ID to ensure compatibility with personal accounts. - Include
offline_accessandCalendars.ReadWritein 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.
After running the app, sign in with a personal Microsoft account when prompted.
Once signed in, the event is created, and calendar events are listed.
Output:
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.
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.