简体   繁体   English

在 Azure AD B2C 注册用户并使用用户名登录

[英]Register a user in Azure AD B2C and login with username

I made an application that creates a user in Azure AD B2C throught Microsoft Graph API我创建了一个应用程序,通过 Microsoft Graph API 在 Azure AD B2C 中创建用户

    var user = new User()
    {
          CreatedDateTime = DateTime.UtcNow,

          MailNickname = command.DocumentNumber,
          UserPrincipalName = $"{command.DocumentNumber}@*********.onmicrosoft.com",

          DisplayName = command.DisplayName,
          GivenName = command.GivenName,
          Surname = command.Surname,
          Mail = command.Mail,
          MobilePhone = command.MobilePhone,
    
          AccountEnabled = true,
          PasswordProfile = new PasswordProfile()
          {
              Password = "ABCabc123!*.",
              ForceChangePasswordNextSignIn = true
          },

          CreationType = "LocalAccount",
          PreferredLanguage = "es-ES",

          Identities = new List<ObjectIdentity>
          {
             new ObjectIdentity()
             {
                SignInType = "userName",
                Issuer = "******.onmicrosoft.com",
                IssuerAssignedId = command.DocumentNumber
            }
        }
    };


    var graphClient = _graphService.GetGraphServiceClient();

    var userCreated = await graphClient.Users.Request().AddAsync(user);

After that, we can see the user inside Azure AD B2C之后,我们可以看到Azure AD B2C里面的用户

在此处输入图像描述

Then, I want to reset password with specific User Flow created in B2C but it returns an error: An account could not be found for the provided user ID.然后,我想使用在 B2C 中创建的特定用户流程重置密码,但它返回错误:找不到提供的用户 ID 的帐户。

在此处输入图像描述

Any suggestion?有什么建议吗?

From your first screenshot, I can see that you added a user with name Sergio[...] and user name 53[...] .从您的第一个屏幕截图中,我可以看到您添加了一个名为Sergio[...]和用户名53[...]的用户。 Then I guess that you try to reset the password with 53[...] as Id but 53[...] is the user name.然后我猜您尝试使用53[...]作为Id重置密码,但53[...]是用户名。

When creating a user , a guid is generated which is then used as Id .创建用户时,会生成一个 guid,然后将其用作Id You have to use this Id or the userPrincipalName because these values are unique and enable to identify the specific user.您必须使用此IduserPrincipalName ,因为这些值是唯一的并且能够识别特定用户。

Here is an example response you get after creating a new user:以下是您在创建新用户后收到的示例响应:

HTTP/1.1 201 Created
Content-type: application/json

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity",
    "id": "87d349ed-44d7-43e1-9a83-5f2406dee5bd",
    "businessPhones": [],
    "displayName": "Adele Vance",
    "givenName": "Adele",
    "jobTitle": "Product Marketing Manager",
    "mail": "AdeleV@contoso.onmicrosoft.com",
    "mobilePhone": "+1 425 555 0109",
    "officeLocation": "18/2111",
    "preferredLanguage": "en-US",
    "surname": "Vance",
    "userPrincipalName": "AdeleV@contoso.onmicrosoft.com"
}

Response copied from Create a user .创建用户复制的响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM