0

I am developing an ASP.Net core web application with Azure AD authentication , When the user is logged in, I need to get all the groups he is a member of and his basic details, Any Leads would be appreciated,

Thanks In Advance.

1
  • Please, read [here](How do I ask a good question?) and edit your question. Commented Aug 16, 2018 at 14:14

1 Answer 1

1

Group Ids are available as claims that come as part of the auth token that you get from Azure AD. The specific claim name is "groups".

In your .NET code it will be available as part of the ClaimsIdentity for user.

Here is sample code which shows how to perform or restrict different actions in your application based on the groups for logged in user - https://github.com/Azure-Samples/active-directory-dotnet-webapp-groupclaims#authorization-in-a-web-app-using-azure-ad-groups--group-claims

Specifically for finding groups that logged in user is a member of, look at this code in the shared sample -

public class ClaimHelper
    {
        public static async Task<List<string>> GetGroups(ClaimsIdentity claimsId)
        {
            if (claimsId.FindFirst("_claim_names") != null
                && (Json.Decode(claimsId.FindFirst("_claim_names").Value)).groups != null)
                return await GetGroupsFromGraphAPI(claimsId);

            return claimsId.FindAll("groups").Select(c => c.Value).ToList();
        }

Here is a link that explains all the different claims that will be available to you. - https://learn.microsoft.com/en-us/azure/active-directory/develop/v1-id-and-access-tokens

First Name, Last Name, Object Id, Groups and User Principal Name might provide you what you're looking for.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.