驗證註冊期間收集的屬性
練習 - 驗證註冊期間收集的屬性
自訂驗證延伸模組支援在屬性集合提交時事件。 此事件可讓您驗證在註冊期間向使用者收集的屬性。 針對我們的雜貨網站,我們會根據自訂驗證延伸模組 REST API 中編譯的國家/地區清單來驗證 [城市] 名稱。 此外,如果城市包含區塊,Microsoft Entra 外部 ID 會顯示區塊頁面。 如果城市包含修改,Microsoft Entra 外部 ID 會修改部分屬性 (顯示名稱和城市)。
注意
您至少需要驗證擴充性系統管理員目錄角色,才能設定註冊期間收集的屬性驗證。
此為特殊權限角色。 請參閱使用特殊權限角色的最佳做法。
想提供意見反應? 請讓我們知道您的概念證明專案進行狀況如何。 我們很樂意收到您的寶貴意見。
提示
您也可以在此處 (英文) 檢視 .NET C# Web API 的範例,其中示範如何針對各種事件使用 Microsoft Entra 外部 ID 的自訂驗證延伸模組。
首先,註冊 Microsoft Entra 外部 ID 用來呼叫 REST API 的自訂驗證延伸模組。 自訂驗證延伸模組包含 REST API 端點的相關資訊、其剖析自 REST API 的屬性收集啟動動作,以及向 REST API 進行驗證的方式。 登入 Microsoft Entra 系統管理中心,並瀏覽至 [外部身分識別]>[自訂驗證延伸模組]。 請注意,您也可以瀏覽至 [應用程式]>[企業應用程式]>[自訂驗證延伸模組]。 然後,選取 [建立自訂延伸模組]。
在 [基本] 中,選取 AttributeCollectionSubmit 事件,然後選取 [下一步]。
在 [端點設定] 中,填入下列屬性:
為了確保自訂驗證延伸模組與 REST API 之間的通訊受到適當保護,您必須套用多個安全性控制項。 第一個步驟是建立或選擇 Microsoft Entra 外部 ID 所使用的應用程式。 該解決方案會使用 OAuth 2.0 用戶端認證授與流程,以保護對 API 端點的呼叫。
如果這是您的第一個自訂驗證延伸模組,請參閱我們設定 TokenIssuanceStart 事件 (英文) 的方式。 由於我們已經設定自訂驗證延伸模組,請在 [API 驗證] 中,選擇 [選取此目錄中現有的應用程式註冊] 選項。
選取您為其他自訂驗證延伸模組設定的應用程式,然後選擇 [選取]。
檢閱您的設定,然後選取 [建立] 以註冊您設定的自訂驗證延伸模組,以及您選取的相關聯應用程式註冊。
目前,您的租用戶中已設定自訂驗證延伸模組,但未用於任何註冊頁面。 接下來,您要自訂驗證延伸模組關聯至一或多個使用者流程。 為此,請瀏覽至 [身分識別]>[外部身分識別]>[使用者流程]。 然後,從清單中選取使用者流程。
從功能表中,選取 [自訂驗證延伸模組]。 若要關聯您的自訂驗證延伸模組,請選取 [向使用者收集資訊之前]。
系統會顯示針對 OnAttributeCollectionStart 事件設定的自訂延伸模組。 為屬性收集開始事件選取其中一個項目,然後選擇 [選取] 以儲存變更。
做得好!您已建立 OnAttributeCollectionSubmit 類型的自訂驗證延伸模組,並將其關聯至您的使用者流程。
1.註冊自訂驗證延伸模組應用程式
如果這是您的第一個自訂驗證延伸模組,請註冊自訂驗證延伸模組應用程式 (英文)。
2.註冊自訂驗證延伸模組
接下來,您需要註冊自訂驗證延伸模組 (英文)。 若要註冊自訂驗證延伸模組,您可以將該模組關聯至您建立的自訂驗證延伸模組安全性應用程式,以及您的 REST API 端點。 將下列值取代為您自己的值: - {app-ID} 取代為上一個呼叫自訂驗證延伸模組安全性應用程式的應用程式識別碼。 - {REST-API-domain} 取代為您的 REST API 網域名稱 - {Endpoint-URL} - 取代為 REST API 端點的 URL
POST https://graph.microsoft.com/beta/identity/customAuthenticationExtensions
{
"@odata.type": "#microsoft.graph.onAttributeCollectionSubmitCustomExtension",
"displayName": "Validate sign-up user input",
"description": "Validate user input including the city name and may ask the user to correct the data or block the user",
"behaviorOnError": null,
"authenticationConfiguration": {
"@odata.type": "#microsoft.graph.azureAdTokenAuthentication",
"resourceId": "api://{REST-API-domain}/{app-ID}"
},
"endpointConfiguration": {
"@odata.type": "#microsoft.graph.httpRequestEndpoint",
"targetUrl": "{Endpoint-URL}"
},
"clientConfiguration": {
"timeoutInMilliseconds": null,
"maximumRetries": null
}
}
範例
POST https://graph.microsoft.com/beta/identity/customAuthenticationExtensions
{
"@odata.type": "#microsoft.graph.onAttributeCollectionSubmitCustomExtension",
"displayName": "Validate sign-up user input",
"description": "Validate user input including the city name and may ask the user to correct the data or block the user",
"behaviorOnError": null,
"authenticationConfiguration": {
"@odata.type": "#microsoft.graph.azureAdTokenAuthentication",
"resourceId": "api://auth-api.woodgrovedemo.com/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1"
},
"endpointConfiguration": {
"@odata.type": "#microsoft.graph.httpRequestEndpoint",
"targetUrl": "https://auth-api.woodgrovedemo.com/OnAttributeCollectionSubmit"
},
"clientConfiguration": {
"timeoutInMilliseconds": null,
"maximumRetries": null
}
}
2.1 複製自訂驗證延伸模組識別碼
從回應中,複製 id 的值。例如:
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#identity/customAuthenticationExtensions/$entity",
"@odata.type": "#microsoft.graph.onAttributeCollectionStartCustomExtension",
"id": "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb",
"displayName": "Prepopulate sign-up attributes",
"description": "Prepopulate sign-up attributes from a REST API",
}
2.2 建立驗證事件接聽程式
註冊自訂驗證延伸模組之後,請建立驗證事件接聽程式 (英文)。 在下一個 JSON 中,將 {Custom-auth-extension-ID} 取代為您剛才建立的自訂驗證延伸模組。
POST https://graph.microsoft.com/beta/identity/authenticationEventListeners
{
"@odata.type": "#microsoft.graph.onAttributeCollectionSubmitListener",
"conditions": {
"applications": {
"includeAllApplications": false,
"includeApplications": []
}
},
"priority": 500,
"handler": {
"@odata.type": "#microsoft.graph.onAttributeCollectionSubmitCustomExtensionHandler",
"customExtension": {
"id": "{Custom-auth-extension-ID}"
}
}
}
範例
POST https://graph.microsoft.com/beta/identity/authenticationEventListeners
{
"@odata.type": "#microsoft.graph.onAttributeCollectionSubmitListener",
"conditions": {
"applications": {
"includeAllApplications": false,
"includeApplications": []
}
},
"priority": 500,
"handler": {
"@odata.type": "#microsoft.graph.onAttributeCollectionSubmitCustomExtensionHandler",
"customExtension": {
"id": "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb"
}
}
}
2.3 將自訂驗證延伸模組連結至使用者流程
更新您的使用者流程 (英文)。 在下列要求中,以您自己的值取代下列值: - {user-flow-ID} 取代為您的使用者流程識別碼 (英文)。 - {Custom-auth-extension-ID} 取代為您剛才建立的自訂驗證延伸模組。
PUT https://graph.microsoft.com/beta/identity/authenticationEventsFlows/{user-flow-ID}/microsoft.graph.externalUsersSelfServiceSignUpEventsFlow/onAttributeCollectionSubmit/microsoft.graph.onAttributeCollectionSubmitCustomExtensionHandler/customExtension/$ref
{
"@odata.id": "https://graph.microsoft.com/beta/identity/customAuthenticationExtensions/{Custom-auth-extension-ID}"
}
範例
PUT https://graph.microsoft.com/beta//identity/authenticationEventsFlows/bbbbbbbb-1111-2222-3333-cccccccccccc/microsoft.graph.externalUsersSelfServiceSignUpEventsFlow/onAttributeCollectionSubmit/microsoft.graph.onAttributeCollectionSubmitCustomExtensionHandler/customExtension/$ref
{
"@odata.id": "https://graph.microsoft.com/beta/identity/customAuthenticationExtensions/aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb"
}