The process of building custom applications and tools that interact with Microsoft SharePoint, including SharePoint Online in Microsoft 365.
Please note that our forum is a public platform, and we will modify your question to hide your personal information in the description. Kindly ensure that you hide any personal or organizational information the next time you post an error or other details to protect personal data.
Hi @Selvakumar K
First, I’d like to clarify that this is a user‑to‑user support forum. Moderators participating here do not have access to backend systems, nor can we directly intervene in Microsoft product functionality. Our role is limited to providing technical guidance and sharing best‑practice recommendations based on reported issues, requests, and scenarios.
Regarding your concerns:
Any misconfiguration in SharePoint Online for app-only authentication
As far as I know, the 401 Unauthorized error is most likely related to the Azure AD application not being granted the required Application permissions for SharePoint Online.
At this time, your application may be able to successfully obtain an access token. However, SharePoint rejects the token because the application permissions have not been approved by an administrator.
Please ensure the following configuration:
In Azure AD App Registration > API Permissions.
Add SharePoint > Application permissions (for example, Sites.ReadWrite.All).
Note: Do not use Delegated permissions for app-only authentication and Global Administrator must click “Grant admin consent”.
Without admin consent for Application permissions, SharePoint Online will always return 401 Unauthorized, even if the access token is successfully issued.
For changes required in the code for .NET 4.0 to work with modern Azure AD app-only authentication:
Based on my research, modern Azure AD app-only authentication no longer supports client secrets for SharePoint Online in many scenarios. Instead, Microsoft requires certificate-based authentication.
You could try to replace the client secret with an X.509 certificate (.pfx)
The application must generate and sign a JWT client assertion using that certificate
Because .NET Framework 4.0 is very old, it is not supported by modern Microsoft authentication libraries, such as:
MSAL.NET (Microsoft.Identity.Client)
PnP.Framework
These libraries handle certificate-based authentication automatically, but they require .NET Framework 4.6.2 or later.
With .NET 4.0, you would need to implement custom cryptographic logic to manually generate and sign JWT assertions, which is complex and error-prone.
You may consider upgrading the application to .NET Framework 4.6.2 or higher so that MSAL.NET can be used, allowing certificate-based app-only authentication to be implemented with minimal code.
Reference: Avoiding Access Errors with SharePoint App-Only Access
Regarding to v1 vs. v2 endpoint
Its might not relevant. Looks like your code successfully retrieves an access token means the endpoints (v1 or v2) and the parameters (scope or resource) are working perfectly fine at the Azure AD level. The 401 Unauthorized error is thrown by SharePoint, not Azure AD. SharePoint decodes your valid token, looks at how it was generated, sees that it originated from a Client Secret, and intentionally blocks the connection. Changing between v1 and v2 will not bypass SharePoint's restriction on Client Secrets.
Additionally, I recommend decoding the access token (JWT) to verify why SharePoint returns 401.
To clearly identify the root cause, we recommend decoding the access token (JWT) using https://jwt.ms.
Note: This link may reference Microsoft-related content but is not hosted on an official Microsoft domain (such as .microsoft.com). Please note that Microsoft is not responsible for the accuracy, security, or advertising on this site.
Please verify the following claims:
aud must be: https://{tenant}.sharepoint.com
roles must include SharePoint Application permissions, for example: Sites.ReadWrite.All
If the token contains scp (scopes) but does not contain roles, this indicates that the application only has Delegated permissions, which are ignored in app‑only authentication. In this case, SharePoint will always return 401 Unauthorized.
Please note that this summary is based on my own findings and may not fully address your concerns. To help you reach your goal more effectively, I recommend engaging with [GitHub Community Forum] for a deeper technical dive or to connect with individuals who have relevant experience and expertise. Some approaches may behave differently or be restricted depending on your specific environment and configuration. These forums include many experienced developers and Microsoft specialists who can assist with troubleshooting and guidance.
Apologies for redirecting you to the related development team support. As moderators in this community, we do not have access to your specific tenant configuration, and my testing environment is limited. Therefore, my guidance is based on available Microsoft documentation and resources. That said, I’ll do my best to provide additional insight where possible.
I hope this helps.
If you have any additional concerns, feel free to comment below. I would be more than happy to assist.
Note: Please follow the steps in [our documentation] to enable e-mail notifications if you want to receive the related email notification for this thread.