I’m building a simple demo application netcoreapp6.0
where I offer a sign-in button to log in users against Azure AD.
For the initial login we request basic claims like ‘user.read’.
Now we need to acquire additional claims from our users as soon as the open specific pages on the website.
I can’t get around how to acquire these claims after the user already authenticated.
Microsoft has consent
buttons on https://developer.microsoft.com/en-us/graph/graph-explorer
which do exactly what I need. However, I can’t find any documentation on the /common/reprocess/
endpoint they are using.
What we’ve tried so far:
Adding claims policies:
services.AddAuthorization(options => {
options.AddPolicy("ClaimsTest", policy => policy.RequireClaim("Contacts.Read"));
options.AddPolicy("MustHaveOneDrive", policy => policy.RequireClaim("Files.ReadWrite"));
});
And then checking those claims like:
[Authorize(Policy="MustHaveOneDrive")]
This works. If the user does not provide the claims, access is denied.
I now want to have the app to ask the user for the required claims just like Microsoft does in thei graph explorer.
I can’t provide code for this as we have no idea where to start.
2
Answers
Thanks for the help so far!
We've managed to succeed:
What we've done: In
startup.cs
And that's basically it. Not too hard but hard to find (for us).
With the middleware set up we can no do this (working example):
somePage.cshtml.cs
:Add annotation tags for any upcoming scopes you might want to incrementally add.
This now requests a new set of claims if not already provided by the user. Hope this helps someone in the future!
Feel free to make sugestions if we're doing anything weird here!
The authentication config in appsettings.json looks like this:
For additional consent using the Auth API,could you please check and follow these steps:
ref doc – https://github.com/MicrosoftDocs/msteams-docs/blob/main/msteams-platform/tabs/how-to/authentication/tab-sso-graph-api.md
Hope this will help , please let us know you need something else
Thank you