If your app is running in the context of a user, use the /me/memberof endpoint. Else, use /users/{id}/memberof: https://learn.microsoft.com/en-us/graph/api/user-list-memberof?view=graph-rest-1.0&tabs=http
Also take a look at the /transitiveMemberOf query.
How i can Get all Groups from Azure Active Directory via C# code
Hello,
I am using Azure Active Directory Authentication in Blazor Webassembly Application and its working as expected but i need to fetch all Groups which are assign to a user who logged in .
Microsoft Security | Microsoft Graph
2 answers
Sort by: Most helpful
-
Vasil Michev 119.7K Reputation points MVP Volunteer Moderator
2022-09-14T11:10:58.057+00:00 -
JamesTran-MSFT 36,911 Reputation points Microsoft Employee Moderator
2022-09-15T21:16:13.633+00:00 @Kuldeep Y
Thank you for your post!Adding onto what was shared by @Vasil Michev , you should be able to leverage the List a user's direct memberships Graph REST API to get groups, directory roles, and administrative units that the user is a direct member of.
#Example 1: Get groups, directory roles, and administrative units that the user is a direct member of GraphServiceClient graphClient = new GraphServiceClient( authProvider ); var memberOf = await graphClient.Users["{user-id}"].MemberOf .Request() .GetAsync();
For more details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation.
- Install a Microsoft Graph SDK
- Create a Microsoft Graph client
- Customize the Microsoft Graph SDK service client
- Choose a Microsoft Graph authentication provider based on scenario
- Make API calls using the Microsoft Graph SDKs
Additional Links:
Getting started on managing users and groups using C#
Getting started on managing users and groups using C# - GitHub Repo
Querying Azure AD using c# console application - This Stack Overflow post share some more samples using the graph API to get User infoI hope this helps!
If you have any other questions, please let me know.
Thank you for your time and patience throughout this issue.----------
Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.