protected virtual async Task <AuthenticateResult> ProcessNewExternalAccountAsync(string provider, string providerId, IEnumerable <Claim> claims) { var user = await TryGetExistingUserFromExternalProviderClaimsAsync(provider, claims); if (user == null) { user = await InstantiateNewUserFromExternalProviderAsync(provider, providerId, claims); if (user == null) { throw new InvalidOperationException("CreateNewAccountFromExternalProvider returned null"); } var createResult = await _userStore.CreateAsync(user); if (!createResult.Succeeded) { return(new AuthenticateResult(createResult.Errors.First())); } } var externalLogin = new ExternalLoginInfo(provider, providerId); var addExternalResult = await _userStore.AddLoginAsync(user.Id, externalLogin); if (!addExternalResult.Succeeded) { return(new AuthenticateResult(addExternalResult.Errors.First())); } var result = await AccountCreatedFromExternalProviderAsync(user.Id, provider, providerId, claims); if (result != null) { return(result); } return(await SignInFromExternalProviderAsync(user.Id, provider)); }