I noticed that I can enable Windows Auth in my ASP.NET Core app by enabling windowsAuthentication
parameter in my launchSettings.json
file:
"iisSettings": {
"windowsAuthentication": true,
"anonymousAuthentication": false,
"iisExpress": {
// ...
}
Is there an easy way to make the authentication a bit more restrictive and allow only users who belong to a specific group in my domain?
I remember implementing this once manually and now I wonder if a feature like this is supported by .NET automatically.
I use .NET6.
EDIT
Something I have in mind (it's not a valid code, rather loud-thinking):
app.UseRouting();
app.Use(async (context, next) =>
{
if (userBelongsToGroup(@"MySuperGroup"))
{
await next();
}
else
{
context.Response.StatusCode = 401;
return;
}
});
app.UseAuthorization();