Set LoginProvider when ExternalLoginConfirmation fails (#187)
Addresses #98
This commit is contained in:
parent
4d2e642b94
commit
26ea920fa6
|
|
@ -72,7 +72,7 @@ namespace Company.WebApplication1.Pages.Account
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sign in the user with this external login provider if the user already has a 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, bypassTwoFactor : true);
|
var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent: false, bypassTwoFactor: true);
|
||||||
if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("{Name} logged in with {LoginProvider} provider.", info.Principal.Identity.Name, info.LoginProvider);
|
_logger.LogInformation("{Name} logged in with {LoginProvider} provider.", info.Principal.Identity.Name, info.LoginProvider);
|
||||||
|
|
@ -100,14 +100,15 @@ namespace Company.WebApplication1.Pages.Account
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostConfirmationAsync(string returnUrl = null)
|
public async Task<IActionResult> OnPostConfirmationAsync(string returnUrl = null)
|
||||||
{
|
{
|
||||||
|
// Get the information about the user from the external login provider
|
||||||
|
var info = await _signInManager.GetExternalLoginInfoAsync();
|
||||||
|
if (info == null)
|
||||||
|
{
|
||||||
|
throw new ApplicationException("Error loading external login information during confirmation.");
|
||||||
|
}
|
||||||
|
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
// Get the information about the user from the external login provider
|
|
||||||
var info = await _signInManager.GetExternalLoginInfoAsync();
|
|
||||||
if (info == null)
|
|
||||||
{
|
|
||||||
throw new ApplicationException("Error loading external login information during confirmation.");
|
|
||||||
}
|
|
||||||
var user = new ApplicationUser { UserName = Input.Email, Email = Input.Email };
|
var user = new ApplicationUser { UserName = Input.Email, Email = Input.Email };
|
||||||
var result = await _userManager.CreateAsync(user);
|
var result = await _userManager.CreateAsync(user);
|
||||||
if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
|
|
@ -126,6 +127,7 @@ namespace Company.WebApplication1.Pages.Account
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LoginProvider = info.LoginProvider;
|
||||||
ReturnUrl = returnUrl;
|
ReturnUrl = returnUrl;
|
||||||
return Page();
|
return Page();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -307,14 +307,15 @@ namespace Company.WebApplication1.Identity.Controllers
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
public async Task<IActionResult> ExternalLoginConfirmation(ExternalLoginViewModel model, string returnUrl = null)
|
public async Task<IActionResult> ExternalLoginConfirmation(ExternalLoginViewModel model, string returnUrl = null)
|
||||||
{
|
{
|
||||||
|
// Get the information about the user from the external login provider
|
||||||
|
var info = await _signInManager.GetExternalLoginInfoAsync();
|
||||||
|
if (info == null)
|
||||||
|
{
|
||||||
|
throw new ApplicationException("Error loading external login information during confirmation.");
|
||||||
|
}
|
||||||
|
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
// Get the information about the user from the external login provider
|
|
||||||
var info = await _signInManager.GetExternalLoginInfoAsync();
|
|
||||||
if (info == null)
|
|
||||||
{
|
|
||||||
throw new ApplicationException("Error loading external login information during confirmation.");
|
|
||||||
}
|
|
||||||
var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
|
var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
|
||||||
var result = await _userManager.CreateAsync(user);
|
var result = await _userManager.CreateAsync(user);
|
||||||
if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
|
|
@ -327,9 +328,11 @@ namespace Company.WebApplication1.Identity.Controllers
|
||||||
return RedirectToLocal(returnUrl);
|
return RedirectToLocal(returnUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AddErrors(result);
|
AddErrors(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ViewData["LoginProvider"] = info.LoginProvider;
|
||||||
ViewData["ReturnUrl"] = returnUrl;
|
ViewData["ReturnUrl"] = returnUrl;
|
||||||
return View(nameof(ExternalLogin), model);
|
return View(nameof(ExternalLogin), model);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue