public async Task TryConnectExternalLoginToUser(IdentityUser user, string providerUserId, AuthenticateResult result) { if (user == null) { throw new ArgumentNullException(nameof(user)); } var email = result.Principal.Claims.FindEmail(); var provider = result.Properties.Items["scheme"]; var providerDisplayName = await _authenticationSchemeProvider.GetProviderDisplayName(provider); var identityResult = await _userManager.AddLoginAsync(user, new UserLoginInfo(provider, providerUserId, providerDisplayName), email); if (!identityResult.Succeeded) { throw new Exception(identityResult.Errors.First().Description); } }