Проблема в подписании с пользователем БД в IdentityServer4 - PullRequest
0 голосов
/ 07 октября 2018

Я не могу войти в приложение IdentityServer с URL-адресом: /account/login Ниже показаны сообщения:

InvalidOperationException: No IAuthenticationSignInHandler is configured to handle sign in for the scheme: Cookies

Microsoft.AspNetCore.Authentication.AuthenticationService+<SignInAsync>d__13.MoveNext()

CustomIdentityServer4.Controllers.AccountController + d__8.MoveNext () в AccountController.cs

var userIdentity = new ClaimsIdentity(claims, "Password");
var userPrincipal = new ClaimsPrincipal(userIdentity);

await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(userIdentity));

// make sure the returnUrl is still valid, and if yes - redirect back to authorize endpoint
if (_interaction.IsValidReturnUrl(model.ReturnUrl))
{
    return Redirect(model.ReturnUrl);
}
return Redirect("~/");

Я настроил Аутентификацию при запуске:

string connectionString = Configuration.GetConnectionString("DefaultConnection");
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

services.AddDbContext<ApplicationDbContext>(
    options =>
    options.UseSqlServer(connectionString,
                sql => sql.MigrationsAssembly(migrationsAssembly)));//, ServiceLifetime.Transient

services.AddIdentity<ApplicationUser, IdentityRole>()
    .AddEntityFrameworkStores<ApplicationDbContext>()
    .AddDefaultTokenProviders();    

//localization service
services.AddSingleton<LocService>();
services.AddLocalization(options => options.ResourcesPath = "Resources");

services
    .AddMvc()
    .AddViewLocalization(Microsoft.AspNetCore.Mvc.Razor.LanguageViewLocationExpanderFormat.Suffix);

services.Configure<IISOptions>(iis =>
{
    iis.AuthenticationDisplayName = "Windows";
    iis.AutomaticAuthentication = false;
});
var serviceCollection = (ServiceCollection)services;

var builder = services.AddIdentityServer(options =>
    {
        options.Events.RaiseErrorEvents = true;
        options.Events.RaiseInformationEvents = true;
        options.Events.RaiseFailureEvents = true;
        options.Events.RaiseSuccessEvents = true;                    
    })

    .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;
        options.TokenCleanupInterval = 30; // frequency in seconds to cleanup stale grants. 15 is useful during debugging
    });


services.AddAuthentication(options =>
{
    options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
    options.DefaultSignInScheme = IdentityServerAuthenticationDefaults.AuthenticationScheme;
    options.DefaultSignOutScheme = IdentityServerAuthenticationDefaults.AuthenticationScheme;
    options.DefaultChallengeScheme = IdentityServerAuthenticationDefaults.AuthenticationScheme;
    options.DefaultForbidScheme = IdentityServerAuthenticationDefaults.AuthenticationScheme;
    options.DefaultScheme = IdentityServerAuthenticationDefaults.AuthenticationScheme;//IdentityServerConstants.DefaultCookieAuthenticationScheme;
})
.AddIdentityServerAuthentication(JwtBearerDefaults.AuthenticationScheme);

Мне нужно войти в приложение для аутентификации пользователя по запросу OIDC

...