驗證顯示控制項

使用驗證顯示控制項來驗證宣告 (例如電子郵件地址或電話號碼),並將驗證碼傳送給使用者。

VerificationControl 動作

驗證顯示控制項由兩個步驟 (動作) 組成:

  1. 向使用者要求目的地 (例如電子郵件地址或電話號碼),以將驗證碼傳送至該處。 當使用者選取 [傳送代碼] 按鈕時,將會執行驗證顯示控制項的 SendCode 動作SendCode 動作會產生代碼、建構要傳送的內容,並將其傳送給使用者。 地址的值可以預先填入,並作為第二要素驗證。

    傳送代碼動作的範例頁面

  2. 傳送代碼之後,使用者會讀取訊息、將驗證碼輸入顯示控制項所提供的控制項中,然後選取 [驗證代碼]。 選取 [驗證代碼],就會執行 VerifyCode 動作以驗證與地址相關聯的程式碼。 如果使用者選取 [傳送新的程式碼],則會再次執行第一個動作。

    驗證代碼動作的範例頁面

VerificationControl 的必要元素

VerificationControl 必須包含下列元素:

  • DisplayControl 的類型為 VerificationControl
  • DisplayClaims
    • 傳送至 - 一或多個宣告,以指定要將驗證碼傳送至何處。 例如,電子郵件國碼 (地區碼)電話號碼
    • 驗證碼 - 使用者在驗證碼傳送後提供的驗證碼宣告。 此宣告必須設定為必要,且 ControlClaimType 必須設定為 VerificationCode
  • 在使用者完成驗證程序後要傳回至自我判斷提示頁面的輸出宣告 (選擇性)。 例如,電子郵件國碼 (地區碼)電話號碼。 自我判斷技術設定檔會使用宣告來保存資料,或將輸出宣告提升至下一個協調流程步驟。
  • 具有下列名稱的兩個 Action
    • SendCode - 將代碼傳送給使用者。 此動作通常包含兩個驗證技術設定檔,用以產生代碼並加以傳送。
    • VerifyCode - 驗證代碼。 此動作通常包含單一驗證技術設定檔。

在下列範例中,頁面上會顯示 [電子郵件] 文字方塊。 當使用者輸入其電子郵件地址並選取 [SendCode] 時,將會在 Azure AD B2C 後端觸發 SendCode 動作。

然後,使用者可輸入 verificationCode 並選取 [VerifyCode],以在後端觸發 VerifyCode 動作。 如果所有驗證均通過,則會將 VerificationControl 視為完成,使用者可以繼續進行下一個步驟。

<DisplayControl Id="emailVerificationControl" UserInterfaceControlType="VerificationControl">
  <DisplayClaims>
    <DisplayClaim ClaimTypeReferenceId="email"  Required="true" />
    <DisplayClaim ClaimTypeReferenceId="verificationCode" ControlClaimType="VerificationCode" Required="true" />
  </DisplayClaims>
  <OutputClaims>
    <OutputClaim ClaimTypeReferenceId="email" />
  </OutputClaims>
  <Actions>
    <Action Id="SendCode">
      <ValidationClaimsExchange>
        <ValidationClaimsExchangeTechnicalProfile TechnicalProfileReferenceId="GenerateOtp" />
        <ValidationClaimsExchangeTechnicalProfile TechnicalProfileReferenceId="SendGrid" />
      </ValidationClaimsExchange>
    </Action>
    <Action Id="VerifyCode">
      <ValidationClaimsExchange>
        <ValidationClaimsExchangeTechnicalProfile TechnicalProfileReferenceId="VerifyOtp" />
      </ValidationClaimsExchange>
    </Action>
  </Actions>
</DisplayControl>