你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
TOTP 显示控件
使用基于时间的一次性密码 (TOTP) 显示控件,通过 TOTP 方法启用多重身份验证 (MFA)。 最终用户需要使用生成 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
输入声明。
必须按以下顺序调用输入声明转换:
- CreateOtpSecret 的
CreateSecret
声明转换类型。 此声明转换创建一个 TOTP 密钥。 此密钥稍后存储在 Azure AD B2C 的用户配置文件中,并与验证器应用共享。 验证器应用使用此密钥生成用户进行 MFA 所需的 TOTP 代码。 自定义策略使用此密钥来验证用户提供的 TOTP 代码。 - CreateStringClaim 的
CreateIssuer
声明转换类型。 此声明转换创建 TOTP 颁发者名称。 此颁发者名称是租户名称,例如“Contoso demo”。 - FormatStringMultipleClaims 的
CreateUriLabel
声明转换类型。 此声明转换创建 TOTP URI 标签。 此标签是用户唯一标识符(如电子邮件地址)和颁发者名称(例如Contoso demo:emily@fabrikam.com
)的组合。 - BuildUri 的
CreateUriString
声明转换类型。 此声明转换创建 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 自定义策略中定义 Azure AD MFA 技术配置文件。
以下屏幕截图演示了 TOTP 验证页。
后续步骤
- 请参阅定义 Azure AD MFA 技术配置文件,了解如何验证 TOTP 代码。