Visual Studio-generates a bunch of code for AspNet Identity, namely the LoginController and ManageController. In the ManageController there is the following code:
[HttpGet, Route("Manage/LinkLoginCallback")]
public async Task<ActionResult> LinkLoginCallback(string returnUrl)
{
ExternalLoginInfo loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(XsrfKey, User.Identity.GetUserId());
...
var result = await UserManager.AddLoginAsync(User.Identity.GetUserId(), loginInfo.Login);
if (result.Succeeded)
{
...
}
}
The problem I'm having with this code is that UserManager.AddLoginAsync()
throws an exception when an external login with an existing email address is added. However, this seems to be a valid scenario:
- User signed up to Google Plus with email: [email protected]
- User used same email to sign up for Facebook.
- Now they cannot "Link" both accounts under a single local account in my application because of this exception.
How do I handle this situation and add both accounts? Are there any problems with doing this?