在註冊期間收集使用者屬性
練習 - 在註冊期間收集使用者屬性
使用者屬性是在自助式註冊期間向使用者收集的值。 您可以在使用者流程設定中,從想要向客戶收集的 [內建使用者屬性] 集合中選取。 您也可以在註冊期間建立自訂使用者屬性,並將其新增至您的使用者流程。 在註冊頁面上,使用者會輸入資訊,這些資訊會與其設定檔一起儲存在您的目錄中。 為了建立線上雜貨網站,我們會合併使用內建屬性與稱為特殊飲食的自訂屬性。
首先,我們會建立特殊飲食自訂使用者屬性。 若要這樣做,請登入 Microsoft Entra 系統管理中心,並瀏覽至 [外部身分識別]>[概觀]。 然後,選取 [自訂使用者屬性]。
此清單包含租用戶中可用的所有使用者屬性,包括已建立的任何自訂使用者屬性。 [屬性類型] 資料行會指出屬性是內建還是自訂。 選取 [新增] 以新增屬性。
在 [新增屬性] 窗格中,輸入自訂屬性的 [名稱]。 例如,SpecialDiet。 在 [資料類型] 中,選擇 [字串]。 在 [描述] 中,輸入自訂屬性的描述以供內部使用。 使用者看不到此描述。
將自訂使用者屬性新增至租用戶之後,請繼續在註冊流程中加入自訂使用者屬性。 瀏覽至 [身分識別] > [外部身分識別] > [使用者流程]。 然後,從清單中選取使用者流程。
選取 [使用者屬性 ] 。 此清單包含您在上述區段中定義的所有自訂使用者屬性。 例如,新的 SpecialDiet 現在會出現在清單中。 選擇您要在註冊期間向使用者收集的所有屬性,然後選取 [儲存]。
在最後一個步驟中,您會設定註冊頁面配置。 在 [頁面配置] 中,您可以指出需要哪些屬性,並排列顯示順序。 您也可以編輯屬性標籤、建立選項按鈕或核取方塊等等。 針對我們的雜貨網站,我們會在名為 SpecialDiet 的屬性中新增標籤。 在 [自訂] 下方,選取 [頁面配置]。 您選擇要收集的屬性便會出現。 選取 [標籤] 資料列中的值並修改文字,即可編輯任意屬性的標籤。
做得好!您已將自訂屬性新增至租用戶、將自訂屬性新增至使用者流程,然後將標籤新增至屬性。
1.建立自訂屬性
若要建立自訂屬性,請執行下列 Microsoft Graph 要求。
POST https://graph.microsoft.com/beta/identity/userFlowAttributes
{
"displayName": "SpecialDiet",
"description": "Customer's special diet",
"dataType": "string"
}
1.1 複製自訂屬性
從回應中,複製自訂屬性 id 的值。例如:
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#identity/userFlowAttributes/$entity",
"id": "extension_a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1_SpecialDiet",
"displayName": "SpecialDiet",
"description": "Customer's special diet",
"userFlowAttributeType": "custom",
"dataType": "string"
}
2.將屬性新增至使用者流程
若要將屬性新增至使用者流程,請執行下列 Microsoft Graph 要求。 將 {user-flow-ID} 取代為您的使用者流程識別碼. 將 {attribute-ID} 取代為上一個步驟中的屬性識別碼。
POST https://graph.microsoft.com/beta/identity/authenticationEventsFlows/{user-flow-ID}/microsoft.graph.externalUsersSelfServiceSignUpEventsFlow/onAttributeCollection/microsoft.graph.onAttributeCollectionExternalUsersSelfServiceSignUp/attributes/$ref
{
"@odata.id":"https://graph.microsoft.com/beta/identity/userFlowAttributes/{attribute-ID}"
}
範例
POST https://graph.microsoft.com/beta/identity/authenticationEventsFlows/{user-flow-ID}/microsoft.graph.externalUsersSelfServiceSignUpEventsFlow/onAttributeCollection/microsoft.graph.onAttributeCollectionExternalUsersSelfServiceSignUp/attributes/$ref
{
"@odata.id":"https://graph.microsoft.com/beta/identity/userFlowAttributes/{attribute-ID}"
}
3.(選用) 更新頁面配置
屬性通常會出現在註冊頁面底部。 您可以更新註冊頁面配置。 在 [頁面配置] 中,您可以指出需要哪些屬性,並排列顯示順序。 您也可以編輯屬性標籤、建立選項按鈕或核取方塊等等。
若要這樣做,您必須更新使用者流程。 在要求本文中,只提供應更新的屬性值。 要求本文中未包含的現有屬性會保持其先前的值,或根據其他屬性值的變更重新計算。
警告
輸入集合必須包含所有屬性。 若要新增或移除屬性,請務必包含所有其他屬性。
將 {user-flow-ID} 取代為您的使用者流程識別碼. 將 {attribute-ID} 取代為屬性識別碼。
PATCH https://graph.microsoft.com/beta/identity/authenticationEventsFlows/{user-flow-ID}
{
"@odata.type": "#microsoft.graph.externalUsersSelfServiceSignUpEventsFlow",
"onAttributeCollection": {
"@odata.type": "#microsoft.graph.onAttributeCollectionExternalUsersSelfServiceSignUp",
"attributeCollectionPage": {
"customStringsFileId": null,
"views": [
{
"title": null,
"description": null,
"inputs": [
{
"attribute": "email",
"label": "Email Address",
"inputType": "text",
"defaultValue": null,
"hidden": true,
"editable": false,
"writeToDirectory": true,
"required": true,
"validationRegEx": "^[a-zA-Z0-9.!#$%&’'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$",
"options": []
},
{
"attribute": "displayName",
"label": "Display Name",
"inputType": "text",
"defaultValue": null,
"hidden": false,
"editable": true,
"writeToDirectory": true,
"required": true,
"validationRegEx": "^.*",
"options": []
},
{
"attribute": "country",
"label": "Country/Region",
"inputType": "radioSingleSelect",
"defaultValue": null,
"hidden": false,
"editable": true,
"writeToDirectory": true,
"required": false,
"validationRegEx": "^.*",
"options": [
{
"label": "Australia",
"value": "au"
},
{
"label": "Spain",
"value": "es"
},
{
"label": "United States",
"value": "us"
}
]
},
{
"attribute": "city",
"label": "City",
"inputType": "text",
"defaultValue": null,
"hidden": false,
"editable": true,
"writeToDirectory": true,
"required": true,
"validationRegEx": "^.*",
"options": []
}, {
"attribute": "{attribute-ID}",
"label": "Special diet",
"inputType": "text",
"defaultValue": null,
"hidden": false,
"editable": true,
"writeToDirectory": true,
"required": false,
"validationRegEx": "^.*",
"options": []
}
]
}
]
}
}
}