public async Task OnGetAsync(string returnUrl = null) { if (!string.IsNullOrEmpty(ErrorMessage)) { ModelState.AddModelError(string.Empty, ErrorMessage); } returnUrl ??= Url.Content("~/"); // Clear the existing external cookie to ensure a clean login process await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme); ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); ReturnUrl = returnUrl; }
public async Task <ExternalLoginsViewModel> GetExternalLogins(ClaimsPrincipal identityUser) { var user = await GetApplicationUser(identityUser); var vm = new ExternalLoginsViewModel { CurrentLogins = await _userManager.GetLoginsAsync(user) }; vm.OtherLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()) .Where(auth => vm.CurrentLogins.All(ul => auth.Name != ul.LoginProvider)) .ToList(); vm.ShowRemoveButton = await _userManager.HasPasswordAsync(user) || vm.CurrentLogins.Count > 1; return(vm); }
public async Task <IActionResult> OnGetAsync() { var user = await _userManager.GetUserAsync(User); if (user == null) { return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.")); } CurrentLogins = await _userManager.GetLoginsAsync(user); OtherLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()) .Where(auth => CurrentLogins.All(ul => auth.Name != ul.LoginProvider)) .ToList(); ShowRemoveButton = user.PasswordHash != null || CurrentLogins.Count > 1; return(Page()); }
public async Task <IActionResult> ExternalLogins() { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } var model = new ExternalLoginsViewModel { CurrentLogins = await _userManager.GetLoginsAsync(user) }; model.OtherLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()) .Where(auth => model.CurrentLogins.All(ul => auth.Name != ul.LoginProvider)) .ToList(); model.ShowRemoveButton = await _userManager.HasPasswordAsync(user) || model.CurrentLogins.Count > 1; model.StatusMessage = StatusMessage; return(View(model)); }
public async Task OnGetAsync(string returnUrl = null) { ReturnUrl = returnUrl; ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); }