Код: Выделить всё
var result = await SignInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: false);Я даже выполнил простое руководство проверьте, чтобы подтвердить пользователя:
Код: Выделить всё
if (user is not null)
{
userMatch = "YES!";
var passwordCheck = await UserManager.CheckPasswordAsync(user, Input.Password);
if (!passwordCheck)
{
passwordMatch = "NO";
}
else
{
if (!await UserManager.IsEmailConfirmedAsync(user))
{
loginError = "Email not confirmed.";
}
if (await UserManager.IsLockedOutAsync(user))
{
loginError = "Account is locked out.";
}
if (await UserManager.GetTwoFactorEnabledAsync(user))
{
loginError = "Two-factor authentication is required.";
}
}
}
Я использую идентификационный код Microsoft по умолчанию для компонента входа в систему (просто добавлен код выше). Моя конфигурация удостоверения выглядит следующим образом:
Код: Выделить всё
public static IServiceCollection AddIdentityServices(this IServiceCollection services,
IConfiguration configuration)
{
services.AddCascadingAuthenticationState();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddAuthentication(options =>
{
options.DefaultScheme = IdentityConstants.ApplicationScheme;
options.DefaultSignInScheme = IdentityConstants.ExternalScheme;
})
.AddIdentityCookies();
var connectionString = configuration.GetConnectionString("DefaultConnection") ??
throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
services.AddDbContext(options =>
options.UseNpgsql(connectionString));
services.AddDatabaseDeveloperPageExceptionFilter();
services.AddIdentityCore(options =>
{
options.SignIn.RequireConfirmedAccount = true;
options.SignIn.RequireConfirmedEmail = true;
options.User.RequireUniqueEmail = true;
})
.AddEntityFrameworkStores()
.AddSignInManager()
.AddDefaultTokenProviders();
services.AddSingleton();
services.AddScoped();
services.AddScoped();
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo("/app/appData"))
.SetApplicationName(nameof(""));
return services;
}
Код: Выделить всё
Authorization failed. These requirements were not met:
DenyAnonymousAuthorizationRequirement: Requires an authenticated user.
Подробнее здесь: https://stackoverflow.com/questions/793 ... with-login
Мобильная версия