将身份验证添加到Identity Server前端

时间:2018-09-14 18:27:25

标签: c# asp.net-identity identityserver4 asp.net-core-2.1

我已经创建了一个运行Identity Server的Identity Server 4项目,并且已经创建了该项目的前端,以便我们对其进行维护。我遇到的问题是,我无法拥有Identity Server中间件,无法在同一项目中使用身份验证。有没有办法使这两件事起作用?我不想将其分为两个项目。

var builder = services.AddIdentityServer(options =>
{
    options.Events.RaiseErrorEvents = true;
    options.Events.RaiseInformationEvents = true;
    options.Events.RaiseFailureEvents = true;
    options.Events.RaiseSuccessEvents = true;
})
    // this adds the config data from DB (clients, resources)
    .AddConfigurationStore(options =>
    {
        options.ConfigureDbContext = b =>
            b.UseSqlServer(connectionString,
                sql => sql.MigrationsAssembly(migrationsAssembly));
        })
    // this adds the operational data from DB (codes, tokens, consents)
    .AddOperationalStore(options =>
    {
        options.ConfigureDbContext = b =>
            b.UseSqlServer(connectionString,
                sql => sql.MigrationsAssembly(migrationsAssembly));

        // this enables automatic token cleanup. this is optional.
        options.EnableTokenCleanup = true;
        // frequency in seconds to cleanup stale grants. 15 is useful during debugging
        options.TokenCleanupInterval = int.Parse(Configuration.GetSection("TokenCleanup").Value);
    })
    .AddDeveloperSigningCredential();


services.AddIdentity<ApplicationUser, ApplicationRole>().Services.ConfigureApplicationCookie(options =>
{
    options.LoginPath = "/Saml/SingleSignOn";
    options.SlidingExpiration = true;
    options.LogoutPath = "/Saml/SingleSignOn";
    options.Cookie.Expiration = new TimeSpan(1, 0, 0);
    options.Cookie.IsEssential = true;
});

services.AddTransient<IUserStore<ApplicationUser>, CustomUserStore>();
services.AddTransient<IRoleStore<ApplicationRole>, CustomRoleStore>();

services.AddScoped<IUserClaimsPrincipalFactory<ApplicationUser>, MyUserClaimsPrincipalFactory>();

0 个答案:

没有答案