A cloud-based identity and access management service for securing user authentication and resource access
Azure AD Calendar API 401 Unauthorized Error - Need Help
Anthony Pitra
0
Reputation points
Problem Description
I'm getting a 401 Unauthorized error when trying to create calendar events using Microsoft Graph API with Azure AD authentication. The error occurs specifically when calling the /me/events endpoint to create calendar events.
When calling /me is working well.
Current Setup
- Application Type: Web application using NextAuth.js
- Authentication Flow: Authorization Code flow with PKCE
- Scopes Requested: openid profile email offline_access https://graph.microsoft.com/User.Read https://graph.microsoft.com/Calendars.ReadWrite
- Token Type: Delegated permissions (user-based)
Error Details
- Status Code: 401 Unauthorized
- Error: GraphError from @microsoft/microsoft-graph-client
- Endpoint: /me/events (POST request)
- Authentication: Azure AD OAuth2 with delegated permissions
Current Setup
- Application Type: Web application using NextAuth.js
- Authentication Flow: Authorization Code flow with PKCE
- Scopes Requested: openid profile email offline_access https://graph.microsoft.com/User.Read https://graph.microsoft.com/Calendars.ReadWrite
- Token Type: Delegated permissions (user-based)
What Works
- User authentication succeeds
- Can retrieve user profile (/me endpoint works)
- Token is valid and not expired
- Scopes include Calendars.ReadWrite
What Fails
- Creating calendar events (/me/events POST) returns 401
- Error body shows empty message
- Status code: 401 Unauthorized
Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Entra | Microsoft Entra ID
Sign in to answer