public async Task <IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null)
        {
            if (remoteError != null)
            {
                ModelState.AddModelError(string.Empty, $"Error from external provider: {remoteError}");
                return(View(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);

            if (result.Succeeded)
            {
                _logger.LogInformation(5, "User logged in with {Name} provider.", info.LoginProvider);
                return(RedirectToLocal(returnUrl));
            }
            if (result.RequiresTwoFactor)
            {
                return(RedirectToAction(nameof(SendCode), new { ReturnUrl = returnUrl }));
            }
            if (result.IsLockedOut)
            {
                return(View("Lockout"));
            }
            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("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel {
                    Email = email
                }));
            }
        }
        public async Task <ActionResult> LinkLoginCallback()
        {
            var user = await GetCurrentUserAsync();

            if (user == null)
            {
                return(View("Error"));
            }
            var info = await _signInManager.GetExternalLoginInfoAsync(await _userManager.GetUserIdAsync(user));

            if (info == null)
            {
                return(RedirectToAction(nameof(ManageLogins), new { Message = ManageMessageId.Error }));
            }
            var result = await _userManager.AddLoginAsync(user, info);

            var message = result.Succeeded ? ManageMessageId.AddLoginSuccess : ManageMessageId.Error;

            return(RedirectToAction(nameof(ManageLogins), new { Message = message }));
        }