The process of building custom applications and tools that interact with Microsoft SharePoint, including SharePoint Online in Microsoft 365.
Hi @Ahmed Shamim,
I hope you're having a great day.
The 401 “Unsupported app only token” you’re hitting when calling SITE_URL/_api/web/sitegroups/getbyname(GROUP_NAME)/users is actually expected with your current setup. The key detail here is that SharePoint Online REST APIs do not accept app‑only tokens that are issued using a client ID and client secret. Even though this flow works well with Microsoft Graph, SharePoint REST is stricter and only supports app‑only access when the token is issued using certificate‑based authentication.
To move forward, you’ll need to update your existing Entra ID app registration to use a certificate instead of a secret. This can be a self‑signed certificate if you like. You upload the public key of that certificate to the app registration, then use the private key to request an access token via the client‑credentials flow using a JWT client assertion instead of a client secret. When requesting the token, make sure you are targeting SharePoint directly by using the scope https://{tenant}.sharepoint.com/.default, rather than the Microsoft Graph scope.
It’s also important to double‑check that the permissions are granted on the SharePoint API itself, not just on Graph. The app should have application permissions such as Sites.Read.All, or Sites.FullControl.All if your scenario requires broader access, and admin consent must be granted. Once this is in place and you’re authenticating with a certificate‑based app‑only token, SharePoint will accept the call and you’ll be able to enumerate the users inside the site groups as expected.
After that, your overall approach makes sense. You can resolve SharePoint site group membership through the REST API, extract user emails, and then map those back to Entra ID users and object IDs, combining that data with what you already see from the Graph permissions endpoint.
If you want to dig deeper, the following references walk through this model in detail and are worth a look:
- Avoiding Access Errors with SharePoint App-Only Access | Microsoft Community Hub
- Create a self-signed public certificate to authenticate your application - Microsoft identity platf…
- Granting access via Entra ID App-Only | Microsoft Learn
I hope this answer provides some helpful context for your reference. If you have any updates or further questions, please feel free to leave a comment under this post. I'll be more than happy to follow up and assist further within my scope.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
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.