Skip to content

Commit

Permalink
Updated AddNewUserFromExternalLoginAsync method. Fixes #163
Browse files Browse the repository at this point in the history
  • Loading branch information
iamronakshah committed Feb 21, 2017
1 parent 3d06807 commit 2c8ede4
Showing 1 changed file with 4 additions and 14 deletions.
Expand Up @@ -69,24 +69,14 @@ public async Task<ApplicationUser> AddNewUserFromExternalLoginAsync(string email
ApplicationUser userInfo = _userManager.FindById(userId);
if (userInfo == null)// check user is already added or not
{

userInfo = new ApplicationUser() { Email = email, UserName = email, Id = userId };
//Creating a user with email only. Password not required
IdentityResult result = await _userManager.CreateAsync(userInfo);
_logger.Debug("Result:" + result.Succeeded);
_logger.Debug("Result:" + result.Errors);
}
IList<UserLoginInfo> userLoginInformation = await _userManager.GetLoginsAsync(userId);
if (userLoginInformation.Count > 0)//check already added external oauth detials if it exists so remove it.
await _userManager.RemoveLoginAsync(userId, userLoginInformation[0]);

_logger.Debug("UserLoginInformation Count:" + userLoginInformation.Count);
//Adding external Oauth details
UserLoginInfo userLoginInfo = new UserLoginInfo(_stringConstant.PromactStringName, refreshToken);
var success = await _userManager.AddLoginAsync(userInfo.Id, userLoginInfo);

_logger.Debug("UserLoginInfo Add:" + success.Succeeded);
_logger.Debug("UserLoginInfo Add Error:" + success.Errors);
//Adding external Oauth details
UserLoginInfo userLoginInfo = new UserLoginInfo(_stringConstant.PromactStringName, refreshToken);
var success = await _userManager.AddLoginAsync(userInfo.Id, userLoginInfo);
}
return userInfo;
}

Expand Down

0 comments on commit 2c8ede4

Please sign in to comment.