How to use Windows Active Directory Authentication and Identity Based Claims?

前端 未结 5 1974
一向
一向 2020-12-07 12:21

Problem

We want to use Windows Active Directory to authenticate a user into the application. However, we do not want to use Active Directory groups to manage autho

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 13:07

    On ASPNET5 (beta6), the idea is to use CookieAuthentication and Identity : you'll need to add in your Startup class :

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
        services.AddAuthorization();
        services.AddIdentity()
            .AddUserStore>()
            .AddRoleStore>()
            .AddUserManager()
            .AddDefaultTokenProviders();
    }
    

    In the configure section, add:

    private void ConfigureAuth(IApplicationBuilder app)
    {
        // Use Microsoft.AspNet.Identity & Cookie authentication
        app.UseIdentity();
        app.UseCookieAuthentication(options =>
        {
            options.AutomaticAuthentication = true;
            options.LoginPath = new PathString("/App/Login");
        });
    }
    

    Then, you will need to implement:

    Microsoft.AspNet.Identity.IUserStore
    Microsoft.AspNet.Identity.IRoleStore
    Microsoft.AspNet.Identity.IUserClaimsPrincipalFactory
    

    and extend/override:

    Microsoft.AspNet.Identity.UserManager
    Microsoft.AspNet.Identity.SignInManager
    

    I actually have setup a sample project to show how this can be done. GitHub Link.

    I tested on the beta8 and and with some small adaptatons (like Context => HttpContext) it worked too.

提交回复
热议问题