如何使用 Entra ID 验证安全令牌中的 MFA 声明

概述

许多组织都问过,是否可以根据安全令牌(如 SAML 响应或 OAuth 令牌)中的声明来判断用户是否已完成多因素身份验证 (MFA)。在本文中,我将解释 Entra ID(以前称为 Azure AD)如何在安全令牌中包含这一信息,以及如何针对你的使用场景进行验证。


理解身份验证声明

SAML 和 OAuth 身份验证声明

  • SAML 令牌:Entra ID 使用声明名称http://schemas.microsoft.com/claims/authnmethodsreferences来指示登录过程中使用的身份验证方法。
  • OAuth 令牌:amr(Authentication Methods References,身份验证方法引用)值用于指定 OAuth 令牌中的身份验证方法。

Entra ID 配置

好消息是,Entra ID 默认包含声明http://schemas.microsoft.com/claims/authnmethodsreferences,用于指示是否已完成 MFA。Entra ID 一侧无需其他配置。


如何检查安全令牌中的 MFA 声明

情形 1:仅使用密码登录(未使用 MFA)

如果用户仅使用密码登录(未使用 MFA),声明http://schemas.microsoft.com/claims/authnmethodsreferences将只有一个值:

  • 声明值:
    http://schemas.microsoft.com/ws/2008/06/identity/authenticationmethod/password

令牌中该声明的示例:

<Attribute Name="http://schemas.microsoft.com/claims/authnmethodsreferences">
    <AttributeValue>http://schemas.microsoft.com/ws/2008/06/identity/authenticationmethod/password</AttributeValue>
</Attribute>

情形 2:使用密码和 MFA 登录

如果用户同时使用密码和 MFA 登录(例如身份验证器应用或其他验证方法),声明http://schemas.microsoft.com/claims/authnmethodsreferences将包含两个值:

  • 声明值:
    http://schemas.microsoft.com/ws/2008/06/identity/authenticationmethod/password
    http://schemas.microsoft.com/claims/multipleauthn

令牌中该声明的示例:

<Attribute Name="http://schemas.microsoft.com/claims/authnmethodsreferences">
    <AttributeValue>http://schemas.microsoft.com/ws/2008/06/identity/authenticationmethod/password</AttributeValue>
    <AttributeValue>http://schemas.microsoft.com/claims/multipleauthn</AttributeValue>
</Attribute>

如何验证 MFA 是否完成

要验证 MFA 是否完成,只需检查http://schemas.microsoft.com/claims/multipleauthn值是否存在于声明名称http://schemas.microsoft.com/claims/authnmethodsreferences之下。

  • 如果该值存在:表示 MFA 已完成。
  • 如果该值不存在:表示用户仅使用密码登录。

为什么这很重要

通过检查安全令牌中的声明,你可以通过编程方式确认身份验证期间是否强制执行了 MFA。这对于需要确保遵守安全策略,或与要求 MFA 验证的第三方供应商集成的组织尤其有用。


结论

Entra ID 默认包含必要信息,让验证安全令牌中的 MFA 声明变得简单明了。无论你使用的是 SAML 令牌还是 OAuth 令牌,声明http://schemas.microsoft.com/claims/authnmethodsreferences都提供了你所需的信息,可用于判断用户登录过程中是否完成了 MFA。

如果你要在组织内实施此方法,或需要与合作伙伴或供应商分享,只需向他们提供上文列出的相应声明值即可。


其他资源

发表评论