예제 #1
0
        public async Task <IActionResult> ExternalLoginCallback(string remoteError = null)
        {
            if (remoteError != null)
            {
                ModelState.AddModelError(string.Empty, $"Error from external provider: {remoteError}");
                await FillViewBagWithExternalLoginsAsync();

                return(View(nameof(Login)));
            }

            ExternalLoginResult externalLoginResult = null;

            try
            {
                externalLoginResult = await _accountsService.ExternalLoginAsync();

                if (externalLoginResult.SignInSucceeded || externalLoginResult.CreateUserSucceeded)
                {
                    return(RedirectToAction(IndexActionName, HomeControllerName));
                }

                if (externalLoginResult.IsLockedOut)
                {
                    return(RedirectToAction(nameof(Lockout)));
                }
            }
            catch (ArgumentException e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
            }

            await FillViewBagWithExternalLoginsAsync();

            foreach (var error in externalLoginResult.CreateUserErrors)
            {
                ModelState.AddModelError(string.Empty, error);
            }

            return(View(nameof(Login)));
        }