Create new user

DikongPrigm 61 Reputation points

I do have an ASP.NET Core web api with an Angular frontend and I'm trying to use Facebook Login. Currently, I can successfully login using an angular social login module that I got from angularx-social-login and it returns token and some information about the facebook account. My problem right now is I'm trying to save the facebook credentials into my user store but received an error that I can't add the new facebook user as it doesn't have any password.

public async Task<ActionResult<UserDto>> Facebook([FromBody] FacebookAuthViewModel model)

            var userInfoResponse = await Client.GetStringAsync(
            var userInfo = JsonConvert.DeserializeObject<FacebookUserData>(userInfoResponse);

            var user = await _userManager.FindByEmailAsync(userInfo.Email);

            if (user == null)
                var appUser = new AppUser
                    FirstName = userInfo.FirstName,
                    LastName = userInfo.LastName,
                    FacebookId = userInfo.Id,
                    Email = userInfo.Email,
                    UserName = userInfo.Email,
                    PictureUrl = userInfo.Picture.Data.Url

                await _userManager.CreateAsync(appUser,


            var localUser = await _userManager.FindByNameAsync(userInfo.Email);
            if (localUser == null)
                return BadRequest(new ApiResponse(401, "Failed to create local user account."));

            return new UserDto
                DisplayName = localUser.DisplayName,
                Token = _tokenService.CreateToken(localUser),
                Email = localUser.Email,
A set of technologies in the .NET Framework for building web applications and XML web services.
4,242 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce ( 57,966 Reputation points

    while you can override the password policy, you can just use a dummy password.

    what is the point of creating a user account? your server is just trusting that the client verified the facebook account, rather than verifying the facebook token itself.

  2. Zhi Lv - MSFT 32,046 Reputation points Microsoft Vendor

    Hi @DikongPrigm ,

    To create a password and sign in using your email that you set during the sign in process with external providers:

    Select the Hello <email alias> link at the top-right corner to navigate to the Manage view. Like this (in this sample, I'm using Microsoft login, after click the link the result as below):


    Set a valid password and you can use this to sign in with your email.

    More detail information, see Optionally set password.

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    0 comments No comments