I've read every article and post on this subject, to no avail.
I have an MVC app in azure. I wanted to connect to Azure AD, and get the Groups for a user.
To do this, firstly I altered the Program.cs
// Azure AD
builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"));
Also this:
builder.Services.AddControllersWithViews(options =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
options.Filters.Add(new AuthorizeFilter(policy));
});
Once I did this, it asked me to authenticate when I ran it. I logged in, and it worked. On my MVC page I added @User.Claims.SingleOrDefault(_ => _.Type == "name")?.Value; and it works great.
Next, I wanted to see what groups the user is in.
I followed every guide I could find, but nothing seemed to work. In the user's claims, there is no 'groups' entry or anything suggesting overage (I assume it would appear in claims?).
Now I don't know if I am missing some configuration from my appsettings file? I say this because my appsettings ONLY has this:
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"ClientId": "a guid",
"TenantId": "another guid"
},
It's unclear. After adding the above, I went into Azure and I did various tasks:
My web app : Token configuration > Add groups claim
My web app : API permissions > GroupMember.Read.All (Granted)
My web app : Manifest > change to "groupMembershipClaims": "All"
I also did the same thing in Enterprise applications > MyApp | Single sign-on, I don't know what that is but it was in one of the many posts I read.
What could I possibly be missing that is preventing the groups from appearing?