mustiks
mustiks

Reputation: 55

How to set users rights with Windows Authentication with asp.net core

Please provide guidance on how to set users which may operate in application with Windows Authentication on ASP.NET Core

In Asp.Net MVC 5 I do it with web.config:

<authorization>
      <allow users="domain\foo, domain\bar, domain\baz/>
      <deny users="*" />
</authorization>

How implement this with asp.net core?

Upvotes: 2

Views: 1875

Answers (1)

adem caglin
adem caglin

Reputation: 24123

You can simply write a global authorization policy:

services.AddMvc(config =>
{
    var policy = new AuthorizationPolicyBuilder()
                   .RequireAssertion(x =>
                         x.User.Identity.Name == "domain\\foo" ||
                         x.User.Identity.Name == "domain\\bar" ||
                         x.User.Identity.Name == "domain\\baz")
                   .Build();
   config.Filters.Add(new AuthorizeFilter(policy));
});

Upvotes: 1

Related Questions