How to Fix 401 Unauthorized in SharePoint Azure AD App-Only Authentication
Question details
The user is experiencing a 401 Unauthorized error when using Azure AD app-only authentication in a SharePoint application, specifically during the ExecuteQueryAsync call.

- Product
- Microsoft SharePoint
- Device & OS
- not provided
- Scenario
- Developing or running a SharePoint application that relies on Azure AD app-only authentication.
- Observed behavior
- The application throws a 401 Unauthorized error when attempting to execute queries using ExecuteQueryAsync.
Ensure you have administrative access to both your Azure Active Directory portal and your Microsoft SharePoint admin center to review app registrations and permissions.
Verify Application Credentials and Azure AD Permissions
Check that your Azure AD app registration has the correct tenant ID, client ID, certificate thumbprint, and SharePoint permissions configured.
A 401 Unauthorized error during ExecuteQueryAsync typically indicates that the authentication token is invalid or lacks the necessary scopes. This happens when there is a mismatch in the Azure AD application credentials, an expired certificate, or missing admin consent for SharePoint application permissions.
Log in to the Azure Portal, navigate to Azure Active Directory > App registrations. Select your application and verify that the Application (client) ID and Directory (tenant) ID exactly match your code configuration.
Go to 'Certificates & secrets' in the app registration menu to ensure your uploaded certificate is valid and not expired. Confirm that the thumbprint matches your application's authentication configuration.
Navigate to 'API permissions' and check that the necessary 'SharePoint' permissions are granted under the 'Application' type (e.g., Sites.FullControl.All).
Ensure that the 'Grant admin consent for [Organization]' button has been clicked and successfully applied for the requested SharePoint permissions.

Consult the Microsoft Q&A SharePoint Development Community
If configuration checks do not resolve the issue, consult Microsoft specialists by providing your sanitized code and error logs.
Need a simpler way to manage your documents? Try WPS Office
While SharePoint and Azure AD are powerful for enterprise development, complex authentication errors can slow down your workflow. For everyday document creation, editing, and sharing, WPS Office provides a free, lightweight, and highly compatible alternative to Microsoft Office. Enjoy a familiar interface without the heavy technical overhead.
- 1. Download the Installer: Visit the official WPS Office website and download the free installation package for your operating system.
- 2. Install the Software: Run the downloaded installer file and follow the on-screen prompts to complete the setup process.
- 3. Launch WPS Office: Open WPS Office from your desktop or start menu to instantly begin creating or editing your documents, spreadsheets, and presentations.

Frequently Asked Questions
Why does Azure AD app-only authentication return a 401 error in SharePoint?
A 401 error typically occurs due to mismatched tenant IDs, invalid or expired certificates, incorrect certificate thumbprints, or missing admin consent for SharePoint application permissions in the Azure Portal.
How do I grant admin consent for my SharePoint app in Azure AD?
Go to your app registration in the Azure Portal, click on 'API permissions', add the necessary SharePoint application permissions, and then click the 'Grant admin consent for [Your Organization]' button.
Does WPS Office require Azure AD authentication to edit documents?
No, WPS Office is a standalone office suite. While it offers its own cloud synchronization features, it does not require complex Azure AD app-only authentication configurations to edit standard Office documents locally.




