你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
重要
自 2025 年 5 月 1 日起,Azure AD B2C 将不再可供新客户购买。 在我们的常见问题解答中了解详细信息。
使用基于时间的一次性密码 (TOTP) 显示控件 ,以使用 TOTP 方法启用多因子身份验证。 最终用户需要使用生成 TOTP 代码的验证器应用程序,例如 Microsoft Authenticator 应用程序 或任何其他支持 TOTP 验证的验证器应用程序。
要在自定义策略中启用 TOTP,请使用以下显示控件:
- totpQrCodeControl - 呈现 QR 码和深层链接。 当用户扫描 QR 码或打开深层链接时,身份验证器应用程序将打开,以便用户完成注册过程。
- AuthenticatorAppIconControl - 呈现 Microsoft Authenticator 应用图标,其中包含用于将应用下载到用户移动设备的链接。
- AuthenticatorInfoControl - 呈现 TOTP 简介。
以下屏幕截图显示了显示三个显示控件的 TOTP 注册页面。
以下 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>
显示控件引用自 断言的技术配置文件。 自断言技术配置文件使用输入声明转换来准备所需的 qrCodeContent
输入 secretKey
声明。
必须按以下顺序调用输入声明转换:
-
CreateSecret
CreateOtpSecret 的声明转换类型。 声明转换将创建一个 TOTP 密钥。 此密钥稍后存储在 Azure AD B2C 中的用户配置文件中,并与 Authenticator 应用共享。 身份验证器应用程序使用密钥生成用户需要通过 MFA 的 TOTP 代码。 您的自定义策略使用密钥来验证用户提供的 TOTP 代码。 -
CreateIssuer
CreateStringClaim 的声明转换类型。 声明转换将创建 TOTP 颁发者名称。 颁发者名称是租户名称,例如“Contoso demo”。 -
CreateUriLabel
FormatStringMultipleClaims 的声明转换类型。 claims 转换将创建 TOTP URI 标签。 标签是用户的唯一标识符(如电子邮件地址)和颁发者名称(如Contoso demo:emily@fabrikam.com
)的组合。 -
CreateUriString
BuildUri 的声明转换类型。 声明转换将创建 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 验证页面。
后续步骤
有关多重身份验证的详细信息,请参阅 在 Azure Active Directory B2C 中启用多重身份验证
在 定义 Microsoft Entra ID 多重身份验证技术配置文件中了解如何验证 TOTP 代码。
使用 GitHub 中的任何 Authenticator 应用自定义策略探索具有 TOTP 的示例 Azure AD B2C MFA。