在 Azure Active Directory B2C 中定义自定义属性Define custom attributes in Azure Active Directory B2C

每个面向客户的应用程序对需要收集的信息都有独特的要求。Every customer-facing application has unique requirements for the information that needs to be collected. Azure Active Directory B2C (Azure AD B2C) 租户附带了一组存储在属性中的内置信息:名字、姓氏、城市和邮政编码。Your Azure Active Directory B2C (Azure AD B2C) tenant comes with a built-in set of information stored in attributes, such as Given Name, Surname, City, and Postal Code. 在 Azure AD B2C 中,可以扩展存储在每个客户帐户上的属性集。With Azure AD B2C, you can extend the set of attributes stored on each customer account.

可以在 Azure 门户 中创建自定义属性并将其用于注册用户流、注册或登录用户流或配置文件编辑用户流。You can create custom attributes in the Azure portal and use them in your sign-up user flows, sign-up or sign-in user flows, or profile editing user flows. 还可以使用 Microsoft Graph API 读取和写入这些属性。You can also read and write these attributes by using the Microsoft Graph API.

创建自定义属性Create a custom attribute

  1. 以 Azure AD B2C 租户的全局管理员身份登录 Azure 门户Sign in to the Azure portal as the global administrator of your Azure AD B2C tenant.

  2. 通过在 Azure 门户的右上角切换到包含 Azure AD B2C 租户的目录,确保你正在使用该目录。Make sure you're using the directory that contains your Azure AD B2C tenant by switching to it in the top-right corner of the Azure portal. 选择订阅信息,然后选择“切换目录” 。Select your subscription information, and then select Switch Directory.

    切换到 Azure AD B2C 租户

    选择包含租户的目录。Choose the directory that contains your tenant.

    目录和订阅筛选器中突出显示的 B2C 租户

  3. 选择 Azure 门户左上角的“所有服务” ,搜索并选择 Azure AD B2CChoose All services in the top-left corner of the Azure portal, search for and select Azure AD B2C.

  4. 选择“用户属性” ,然后选择“添加” 。Select User attributes, and then select Add.

  5. 提供自定义属性的“名称” (例如,“ShoeSize”)Provide a Name for the custom attribute (for example, "ShoeSize")

  6. 选择“数据类型” 。Choose a Data Type. 仅“String” 、“Boolean” 和“Int” 可供选择。Only String, Boolean, and Int are available.

  7. (可选)输入“说明” 以供参考。Optionally, enter a Description for informational purposes.

  8. 单击创建Click Create.

现在自定义属性在“用户属性” 列表中显示,以便在用户流中使用。The custom attribute is now available in the list of User attributes and for use in your user flows. 自定义属性只有在任何用户流中第一次使用时才创建,而不是将其添加到“用户属性” 列表时创建。A custom attribute is only created the first time it is used in any user flow, and not when you add it to the list of User attributes.

在用户流中使用自定义属性Use a custom attribute in your user flow

  1. 在 Azure AD B2C 租户中,选择“用户流” 。In your Azure AD B2C tenant, select User flows.
  2. 选择策略(例如,“B2C_1_SignupSignin”)将其打开。Select your policy (for example, "B2C_1_SignupSignin") to open it.
  3. 选择“用户属性” ,然后选择自定义属性(例如,“ShoeSize”)。Select User attributes and then select the custom attribute (for example, "ShoeSize"). 单击“保存” 。Click Save.
  4. 选择“应用程序声明” ,然后选择自定义属性。Select Application claims and then select the custom attribute.
  5. 单击“保存” 。Click Save.

利用使用新创建的自定义属性的用户流创建新用户后,可以在 Microsoft Graph Explorer 中查询该对象。Once you've created a new user using a user flow which uses the newly created custom attribute, the object can be queried in Microsoft Graph Explorer. 或者,可以对用户流使用运行用户流功能来验证客户体验。Alternatively you can use the Run user flow feature on the user flow to verify the customer experience. 现在可以在注册期间收集的属性的列表中看到“ShoeSize” ,并在发送回应用程序的令牌中看到它。You should now see ShoeSize in the list of attributes collected during the sign-up journey, and see it in the token sent back to your application.