如何使用 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。

如果你要把這個做法導入組織,或需要與合作夥伴或廠商分享,只要向他們提供上文列出的相應聲明值即可。


其他資源

發表留言