我的解決方案很簡單。 我只是檢查用戶是否登錄並附加新的社交給他。
public async Task<ActionResult> Callback(string provider)
{
var externalLoginInfo = await _applicationSignInManager.AuthenticationManager.GetExternalLoginInfoAsync();
if (externalLoginInfo == null)
{
return RedirectToAction("Index", "SignIn");
}
// Check if the user with this external login provider already has a login
if (await _applicationSignInManager.UserManager.FindAsync(externalLoginInfo.Login) != null) return RedirectToAction("Index", "Social");
await _applicationSignInManager.UserManager.AddLoginAsync(HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId<long>(), externalLoginInfo.Login);
return RedirectToAction("Index", "Social");
}