Ejemplo n.º 1
0
        public async Task <IActionResult> OnGetCallbackAsync(string returnUrl = null, string remoteError = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (remoteError != null)
            {
                ErrorMessage = Messages.ERRORMESSAGE_EXTERNAL_PROVIDER(remoteError);
                return(RedirectToPage("./Login", new { ReturnUrl = returnUrl }));
            }

            ExternalLoginInfo info = await userService.SignInManager.GetExternalLoginInfoAsync();

            if (info is null)
            {
                ErrorMessage = Messages.ERRORMESSAGE_LOADING_EXTERNAL_INFO;
                return(RedirectToPage("./Login", new { ReturnUrl = returnUrl }));
            }

            // Sign in the user with this external login provider if the user already has a login.
            Microsoft.AspNetCore.Identity.SignInResult result = await userService.SignInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, false, true);

            if (result.Succeeded)
            {
                logger.LogInformation(Messages.LOGGER_INFO_USER_LOGGED_EXTERNAL, info.Principal.Identity.Name, info.LoginProvider);
                return(LocalRedirect(returnUrl));
            }
            if (result.IsLockedOut)
            {
                return(RedirectToPage("./Lockout"));
            }
            else
            {
                // If the user does not have an account, then ask the user to create an account.
                ReturnUrl     = returnUrl;
                LoginProvider = info.LoginProvider;
                if (info.Principal.HasClaim(c => c.Type == ClaimTypes.Email))
                {
                    DateTime.TryParse(info.Principal.FindFirstValue(ClaimTypes.DateOfBirth), out DateTime date);
                    RegisterForm = new UserExternalRegisterBindingModel()
                    {
                        Email     = info.Principal.FindFirstValue(ClaimTypes.Email),
                        FullName  = info.Principal.FindFirstValue(ClaimTypes.Actor),
                        BirthDate = date,
                    };
                }
                return(Page());
            }
        }
Ejemplo n.º 2
0
 public User MapNewExternalUser(UserExternalRegisterBindingModel model) => Mapper.Map <User>(model);