I have a problem and I don't know how I fix it. I have created 1 login function with Facebook and Google. I got my account information but when it was time to call back at ExternalLoginCallback -> _sginInManager.ExternalLoginSignInAsync, I got the error below. I don't know why. Looking forward to all the helpers. Thank you very much!
Here is my error:
NotSupportedException: Store does not implement IUserLoginStore. Microsoft.AspNetCore.Identity.UserManager.GetLoginStore() Microsoft.AspNetCore.Identity.UserManager.FindByLoginAsync(string loginProvider, string providerKey) Microsoft.AspNetCore.Identity.SignInManager.ExternalLoginSignInAsync(string loginProvider, string providerKey, bool isPersistent, bool bypassTwoFactor) ShopAuth.Core.Web.Client.Controllers.AccountController.ExternalLoginCallback(string returnUrl, string remoteError) in AccountController.cs var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent: false, bypassTwoFactor: true); Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor+TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
Here is my code:
UserStore.cs
public class UserStore : IUserStore, IUserEmailStore, IUserPhoneNumberStore, IUserTwoFactorStore, IUserPasswordStore, IUserRoleStore, IUserLockoutStore { private readonly string _connectionString;
public UserStore(IConfiguration configuration) { _connectionString = configuration.GetConnectionString("DbConnectionString"); } // Some impl code here... } AccountController.cs
public AccountController(UserManager<AppUser> userManager, IConfiguration configuration, SignInManager<AppUser> signInManager, IEmailSender emailSender) { _signInManager = signInManager; _userManager = userManager; _configuration = configuration; _connectionString = configuration.GetConnectionString("DbConnectionString"); _emailSender = emailSender; } [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public IActionResult ExternalLogin(string provider, string returnUrl = null) { // Request a redirect to the external login provider. var redirectUrl = Url.Action(nameof(ExternalLoginCallback), "Account", new { returnUrl }); var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl); return Challenge(properties, provider); } [HttpGet] [AllowAnonymous] public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null) { if (remoteError != null) { return RedirectToAction(nameof(Login)); } var info = await _signInManager.GetExternalLoginInfoAsync(); if (info == null) { return RedirectToAction(nameof(Login)); } // Sign in the user with this external login provider if the user already has a login. var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent: false, bypassTwoFactor: true); if (result.Succeeded) { return RedirectToLocal(returnUrl); } if (result.IsLockedOut) { return RedirectToAction(nameof(Logout)); } else { // If the user does not have an account, then ask the user to create an account. ViewData["ReturnUrl"] = returnUrl; ViewData["LoginProvider"] = info.LoginProvider; var email = info.Principal.FindFirstValue(ClaimTypes.Email); return View("ExternalLogin", new ExternalLoginViewModel()); } } [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<IActionResult> ExternalLoginConfirmation(ExternalLoginViewModel model, string returnUrl = null) { if (ModelState.IsValid) { // Get the information about the user from the external login provider var info = await _signInManager.GetExternalLoginInfoAsync(); if (info == null) { throw new ApplicationException("Error loading external login information during confirmation."); } var email = info.Principal.FindFirstValue(ClaimTypes.Email); var user = new AppUser { UserName = email, Email = email, FullName = model.FullName, }; var result = await _userManager.CreateAsync(user); if (result.Succeeded) { result = await _userManager.AddLoginAsync(user, info); if (result.Succeeded) { await _signInManager.SignInAsync(user, isPersistent: false); return RedirectToLocal(returnUrl); } } AddErrors(result); } ViewData["ReturnUrl"] = returnUrl; return View(nameof(ExternalLogin), model); } https://stackoverflow.com/questions/66616224/notsupportedexception-store-does-not-implement-iuserloginstoretuser March 14, 2021 at 01:02AM
没有评论:
发表评论