Fix SharePoint ClientContext 401 Unauthorized Error with Azure AD Token
Question details
The user is experiencing a 401 Unauthorized error when using an Azure AD OAuth access token with SharePoint ClientContext in a .NET Core application.

- Product
- Microsoft SharePoint
- Device & OS
- not provided
- Scenario
- Using SharePoint CSOM app-only authentication in a .NET Core application to connect to SharePoint Online.
- Observed behavior
- An access token from the Azure Access Control endpoint authenticates successfully, but an OAuth token from the Azure AD endpoint returns an HTTP 401 Unauthorized error when sent via the Authorization Bearer header.
Verify that your registered Azure AD application has been granted the correct SharePoint API permissions (such as Sites.Read.All) and that an administrator has provided admin consent for the tenant.
Upgrade to PnP Core SDK for .NET Core
Microsoft recommends using modern libraries like PnP Core SDK or PnP Framework for .NET Core applications as they natively and securely handle Azure AD app-only authentication.
SharePoint CSOM relies on legacy authentication models that do not natively handle Azure AD OAuth tokens seamlessly in .NET Core. Migrating to the modern PnP Core SDK solves this by providing built-in authentication providers for Azure AD.
Open your .NET Core project in Visual Studio, open the NuGet Package Manager, and install the 'PnP.Core.Auth' and 'PnP.Core' packages.
In your 'appsettings.json' file, configure your Azure AD application credentials, including the Client ID, Tenant ID, and your X.509 Certificate or Client Secret.
Use the injected 'IPnPContextFactory' in your application code to seamlessly connect to SharePoint Online. The SDK will automatically request the correct Azure AD token and attach it to the API calls without throwing a 401 error.

Verify the Token Resource and Audience
Ensure your OAuth token request is targeting SharePoint Online directly and not Microsoft Graph or another Microsoft API.
Consult the SharePoint Developer Platform Forum
For highly specific, undocumented API behaviors, reaching out to specialized Microsoft developer forums is the best path to a resolution.
Simplify Your Document Management with WPS Office
While resolving complex SharePoint and Azure AD development issues, you may be looking for a simpler, streamlined way to handle everyday document tasks. WPS Office provides a lightweight, highly compatible alternative to Microsoft Office for creating, editing, and sharing documents without the heavy enterprise overhead.
- 1. Download the Installer: Visit the official WPS Office website and click the free download button for your operating system.
- 2. Install WPS Office: Run the downloaded installer file and follow the quick on-screen instructions to set up the suite.
- 3. Start Creating: Launch WPS Office to instantly open Microsoft Office formats and start collaborating with integrated cloud tools.

Frequently Asked Questions
Why does an Azure Access Control (ACS) token work but Azure AD OAuth fails in CSOM?
Azure ACS tokens use a legacy trust model that SharePoint CSOM natively recognizes for app-only authentication. Modern Azure AD OAuth tokens require a different audience scope and specific API permissions that raw CSOM struggles to parse without proper modern wrappers like the PnP Core SDK.
Can I still use basic authentication with SharePoint CSOM in .NET Core?
No, Microsoft has deprecated and disabled basic authentication across Microsoft 365, including SharePoint Online, for security reasons. All applications must now use modern authentication (OAuth) via Azure Active Directory.
How do I check what API permissions my Azure AD token actually contains?
You can decode your Bearer token using a secure JWT decoder (such as jwt.ms). Look at the 'scp' (scopes) claim for delegated permissions or the 'roles' claim for application permissions to verify if SharePoint API access is properly granted.




