Share via


TOTP 顯示控制項

使用以時間為基礎的單次密碼 (TOTP) 顯示控制項 ,以使用 TOTP 方法啟用多重要素驗證。 終端使用者需要使用產生 TOTP 代碼的驗證器應用程式,例如 Microsoft Authenticator 應用程式 ,或任何其他支援 TOTP 驗證的驗證器應用程式。

若要在自訂原則內啟用 TOTP,請使用下列顯示控制項:

  • totpQrCodeControl - 轉譯 QR 代碼和深層連結。 當使用者掃描 QR 代碼或開啟深層連結時,驗證器應用程式會開啟,讓使用者可以完成註冊程式。
  • AuthenticatorAppIconControl - 轉譯 Microsoft Authenticator 應用程式圖示,其中包含將應用程式下載至使用者行動裝置的連結。
  • AuthenticatorInfoControl - 轉譯 TOTP 簡介。

下列螢幕擷取畫面說明顯示三個顯示控制項的 TOTP 註冊頁面。

Screenshot showing TOTP display controls enrollment flow

下列 XML 程式碼片段顯示三個顯示控制項:

  <DisplayControls>
    <!-- Render the QR code by taking the URI (qrCodeContent) input claim and rendering it as a QR code-->
    <DisplayControl Id="totpQrCodeControl" UserInterfaceControlType="QrCodeControl">
      <InputClaims>
        <InputClaim ClaimTypeReferenceId="qrCodeContent" />
      </InputClaims>
      <DisplayClaims>
        <DisplayClaim ClaimTypeReferenceId="qrCodeContent" ControlClaimType="QrCodeContent" />
      </DisplayClaims>
    </DisplayControl>

    <!-- Render the TOTP information by taking the totpIdentifier and the secretKey input claims and rendering them in plain text-->
    <DisplayControl Id="authenticatorInfoControl" UserInterfaceControlType="AuthenticatorInfoControl">
      <InputClaims>
        <InputClaim ClaimTypeReferenceId="totpIdentifier" />
        <InputClaim ClaimTypeReferenceId="secretKey" />
      </InputClaims>
      <DisplayClaims>
        <DisplayClaim ClaimTypeReferenceId="totpIdentifier" />
        <DisplayClaim ClaimTypeReferenceId="secretKey" />
      </DisplayClaims>
    </DisplayControl>

    <!-- Render the authenticator apps icon. -->
    <DisplayControl Id="authenticatorAppIconControl" UserInterfaceControlType="AuthenticatorAppIconControl" />
  </DisplayControls>

顯示控制項會從 自我判斷技術設定檔 參考。 自我判斷技術設定檔會使用輸入宣告轉換來準備必要 qrCodeContentsecretKey 輸入宣告。

輸入宣告轉換必須依下列順序呼叫:

  1. CreateSecretCreateOtpSecret 宣告轉換類型。 宣告轉換會建立 TOTP 秘密金鑰。 此金鑰稍後會儲存在 Azure AD B2C 中的使用者設定檔中,並與驗證器應用程式共用。 驗證器應用程式會使用 金鑰來產生使用者需要通過 MFA 的 TOTP 程式碼。 您的自訂原則會使用 金鑰來驗證使用者所提供的 TOTP 程式碼。
  2. CreateIssuerCreateStringClaim 宣告轉換類型。 宣告轉換會建立 TOTP 簽發者名稱。 簽發者名稱是您租使用者名稱,例如 「Contoso demo」。
  3. CreateUriLabelFormatStringMultipleClaims 宣告轉換類型。 宣告轉換會建立 TOTP URI 標籤。 標籤是使用者唯一識別碼的組合,例如電子郵件地址和簽發者名稱,例如 Contoso demo:emily@fabrikam.com
  4. CreateUriStringBuildUri 宣告轉換類型。 宣告轉換會建立 TOTP URI 字串。 字串是 URI 標籤和秘密金鑰的組合,例如 otpauth://totp/Contoso%20demo:emily@fabrikam.com?secret=fay2lj7ynpntjgqa&issuer=Contoso+demo 。 此 URI 標籤是由 QR 代碼格式和深層連結的顯示控制項轉譯。

下列 XML 程式碼顯示 EnableOTPAuthentication 自我判斷技術設定檔及其輸入宣告轉換、輸入宣告和顯示控制項。

<TechnicalProfile Id="EnableOTPAuthentication">
  <DisplayName>Sign up with Authenticator app</DisplayName>
  <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.SelfAssertedAttributeProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
  <Metadata>
    <Item Key="ContentDefinitionReferenceId">api.selfasserted.totp</Item>
    <Item Key="language.button_continue">Continue</Item>
  </Metadata>
  <CryptographicKeys>
    <Key Id="issuer_secret" StorageReferenceId="B2C_1A_TokenSigningKeyContainer" />
  </CryptographicKeys>
  <InputClaimsTransformations>
    <InputClaimsTransformation ReferenceId="CreateSecret" />
    <InputClaimsTransformation ReferenceId="CreateIssuer" />
    <InputClaimsTransformation ReferenceId="CreateUriLabel" />
    <InputClaimsTransformation ReferenceId="CreateUriString" />
  </InputClaimsTransformations>
  <InputClaims>
    <InputClaim ClaimTypeReferenceId="qrCodeContent" />
    <InputClaim ClaimTypeReferenceId="secretKey" />
  </InputClaims>
  <DisplayClaims>
    <DisplayClaim DisplayControlReferenceId="authenticatorAppIconControl" />
    <DisplayClaim ClaimTypeReferenceId="QrCodeScanInstruction" />
    <DisplayClaim DisplayControlReferenceId="totpQrCodeControl" />
    <DisplayClaim DisplayControlReferenceId="authenticatorInfoControl" />
  </DisplayClaims>
  <OutputClaims>
    <OutputClaim ClaimTypeReferenceId="objectId" />
    <OutputClaim ClaimTypeReferenceId="secretKey" />
  </OutputClaims>
  <UseTechnicalProfileForSessionManagement ReferenceId="SM-MFA-TOTP" />
</TechnicalProfile>

驗證流程

驗證 TOTP 程式碼是由另一個使用顯示宣告和驗證技術設定檔的自我判斷技術設定檔所完成。 如需詳細資訊,請參閱 在 Azure AD B2C 自訂原則 中定義 Microsoft Entra ID 多重要素驗證技術設定檔。

下列螢幕擷取畫面說明 TOTP 驗證頁面。

Screenshot showing TOTP display controls verification flow

下一步

  • 深入瞭解在 Azure Active Directory B2C 中啟用多重要素驗證中的 多重要素驗證

  • 瞭解如何在定義 Microsoft Entra ID 多重要素驗證技術設定檔 驗證 TOTP 程式碼。

  • GitHub 中使用任何 Authenticator 應用程式自訂原則探索範例 Azure AD B2C MFA 與 TOTP。