public async Task <IActionResult> OnGetCallback() { var result = await HttpContext.AuthenticateAsync(IdentityConstants.ExternalScheme); if (result?.Succeeded != true) { throw new Exception("External authentication error"); } var(user, provider, providerUserId, claims) = await FindUserFromExternalProviderAsync(result); var returnUrl = result.Properties.Items["returnUrl"]; if (user == null) { var email = result.Principal.Claims.FindEmail(); if (email != null && (user = await _userManager.FindByEmailAsync(email)) == null) { // no user found, just add the login to the current user var currentUser = await _userManager.GetUserAsync(User); await TryConnectExternalLoginToUser(currentUser, providerUserId, result); return(ReturnToUrl(returnUrl)); } } // either we have: // * identified a user with the remote login or // * the remote login has an email that matches a local user record or // * we have not found any matching user because missing email claim return(await HandleMerge(user, returnUrl)); }
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); // Updated line CurrentLogins = (await _userManager.GetLoginsEmailInfoAsync(user)).ToList(); OtherLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()) // Upated line //.Where(auth => CurrentLogins.All(ul => auth.Name != ul.LoginProvider)) .ToList(); ShowRemoveButton = user.PasswordHash != null || CurrentLogins.Count > 1; return(Page()); }
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)}'.")); } Emails = _userManager.GetEmails(user); return(Page()); }