Ejemplo n.º 1
0
        public async Task <IActionResult> OnGetAddLinkCallbackAsync(string returnUrl = null, string remoteError = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (remoteError != null)
            {
                StatusMessage = $"Error from external provider: {remoteError}";
                return(Page());
            }
            var info = await _externalLoginService.GetCurrentLoginContextAsync();

            if (info == null)
            {
                StatusMessage = "Error loading external login information during confirmation";
                return(Page());
            }
            var userId = _currentUserService.UserId;
            var result = await _externalLoginService.AddLoginAsync(userId);

            if (result.Succeeded)
            {
                StatusMessage = $"The {info.ProviderName} account was successfully linked";
                _logger.LogInformation("User with ID '{UserId}' linked {ProviderName} account.", userId, info.ProviderName);
                return(RedirectToPage());
            }
            else
            {
                StatusMessage = "An error occured while linking the account";
                return(Page());
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnGetCallbackAsync(string returnUrl = null, string remoteError = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (remoteError != null)
            {
                ErrorMessage = $"Error from external provider: {remoteError}";
                return(RedirectToPage("./Login", new { ReturnUrl = returnUrl }));
            }
            var info = await _externalLoginService.GetCurrentLoginContextAsync();

            if (info == null)
            {
                ErrorMessage = "Error loading external login information during confirmation.";
                return(RedirectToPage("./Login", new { ReturnUrl = returnUrl }));
            }

            var result = await _externalLoginService.SignInAsync();

            if (result.Succeeded)
            {
                _logger.LogInformation("{Name} logged in with {LoginProvider} provider.", info.Principal.Identity.Name, info.ProviderName);
                return(LocalRedirect(returnUrl));
            }
            else
            {
                // If the user does not have an account, then ask the user to create an account.
                ReturnUrl           = returnUrl;
                ProviderDisplayName = info.ProviderName;
                if (info.Principal.HasClaim(c => c.Type == ClaimTypes.Email))
                {
                    Input = new InputModel
                    {
                        Email = info.Principal.FindFirstValue(ClaimTypes.Email)
                    };
                }
                return(Page());
            }
        }