SAML 令牌声明参考

Microsoft 标识平台在每个身份验证流的处理中发出多种安全令牌。 本文档说明 SAML 2.0 令牌的格式、安全特征和内容。

SAML 令牌中的声明

名称 等效 JWT 声明 说明 示例
目标受众 aud 令牌的目标接收方。 接收令牌的应用程序必须验证受众值是否正确,并拒绝任何针对其他受众的令牌。 <AudienceRestriction>
<Audience>
https://contoso.com
</Audience>
</AudienceRestriction>
身份验证即时 记录身份验证发生的日期和时间。 <AuthnStatement AuthnInstant="2011-12-29T05:35:22.000Z">
身份验证方法 amr 标识对令牌使用者进行身份验证的方式。 <AuthnContextClassRef>
http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationmethod/password
</AuthnContextClassRef>
名字 given_name 提供 Microsoft Entra 用户对象上设置的用户的名字。 <Attribute Name="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname">
<AttributeValue>Frank<AttributeValue>
groups 指定表示使用者的组成员身份的对象 ID。 这些值具有唯一性(请参阅对象 ID),可安全地用于管理访问,例如强制要求授权访问资源。 组声明中包含的组通过应用程序清单的“groupMembershipClaims”属性,基于每个应用程序进行配置。 值为 null 将排除所有组;值为“SecurityGroup”将包括目录角色和 Active Directory 安全组成员身份;值为“All”将包括安全组和 Microsoft 365 通讯组列表。

注释
如果用户所在的组数超出了某个限制(对于 SAML,为 150;对于 JWT,为 200),则会添加超额声明,声明源指向包含该用户的组列表的 Graph 终结点。
<Attribute Name="http://schemas.microsoft.com/ws/2008/06/identity/claims/groups">
<AttributeValue>07dd8a60-bf6d-4e17-8844-230b77145381</AttributeValue>
组超额指示器 groups:src1 对于长度不受限制但对于令牌而言仍然太大的令牌请求,将包括指向用户的完整组列表的链接。 对于 SAML,此声明是作为新声明添加的,以代替 groups 声明。

注释
Azure AD 图形 API 正在由 Microsoft Graph API 取代。 若要了解等效终结点的相关详细信息,请参阅 user: getMemberObjects
<Attribute Name=" http://schemas.microsoft.com/claims/groups.link">
<AttributeValue>https://graph.windows.net/{tenantID}/users/{userID}/getMemberObjects<AttributeValue>
标识提供者 idp 记录对令牌使用者进行身份验证的标识提供者。 除非用户帐户与颁发者不在同一租户中,否则此值与颁发者声明的值相同。 <Attribute Name=" http://schemas.microsoft.com/identity/claims/identityprovider">
<AttributeValue>https://sts.windows.net/aaaabbbb-0000-cccc-1111-dddd2222eeee/<AttributeValue>
IssuedAt iat 存储颁发令牌的时间。 它通常用于度量令牌新鲜度。 <Assertion ID="_d5ec7a9b-8d8f-4b44-8c94-9812612142be" IssueInstant="2014-01-06T20:20:23.085Z" Version="2.0" xmlns="urn:oasis:names:tc:SAML:2.0:assertion">
颁发者 iss 标识构造并返回令牌的安全令牌服务 (STS)。 在 Microsoft Entra ID 返回的令牌中,颁发者是 sts.windows.net。 “颁发者声明”值中的 GUID 是 Microsoft Entra 目录的租户 ID。 租户 ID 是目录的固定不变且可靠的标识符。 <Issuer>https://sts.windows.net/aaaabbbb-0000-cccc-1111-dddd2222eeee/</Issuer>
姓氏 family_name 提供 Microsoft Entra 用户对象中定义的用户的姓氏。 <Attribute Name=" http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname">
<AttributeValue>Miller<AttributeValue>
名称 unique_name 提供一个用户可读值,用于标识令牌使用者。 此值不一定在租户中唯一,它旨在仅用于显示目的。 <Attribute Name="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name">
<AttributeValue>frankm@contoso.com<AttributeValue>
对象 ID oid 包含 Microsoft Entra ID 中的对象的唯一标识符。 此值固定不变,无法重新分配或重复使用。 在对 Microsoft Entra ID 进行的查询中,可使用对象 ID 来标识对象。 <Attribute Name="http://schemas.microsoft.com/identity/claims/objectidentifier">
<AttributeValue>528b2ac2-aa9c-45e1-88d4-959b53bc7dd0<AttributeValue>
角色 roles 表示直接和间接通过组成员身份授予使用者的所有应用程序角色,可用于实施基于角色的访问控制。 可通过应用程序清单的 appRoles 属性,对每个应用程序定义应用程序角色。 每个应用程序角色的 value 属性是角色声明中显示的值。 <Attribute Name="http://schemas.microsoft.com/ws/2008/06/identity/claims/role">
Subject sub 标识令牌断言信息的主体,例如应用程序的用户。 此值不可变且不能重新分配或重复使用,因此可以使用它来安全地执行授权检查。 因为使用者始终会在 Microsoft Entra ID 颁发的令牌中存在,我们建议在常规用途授权系统中使用此值。
SubjectConfirmation 不是声明。 它描述如何对令牌的使用者进行验证。 Bearer 指示通过其拥有的令牌确认使用者。
<Subject>
<NameID>S40rgb3XjhFTv6EQTETkEzcgVmToHKRkZUIsJlmLdVc</NameID>
<SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer" />
</Subject>
租户 ID tid 一个不可变且不能重复使用的标识符,用于标识颁发令牌的目录租户。 可以使用此值访问多租户应用程序中特定于租户的目录资源。 例如,可以在调用 Graph API 时使用此值标识租户。 <Attribute Name="http://schemas.microsoft.com/identity/claims/tenantid">
<AttributeValue>aaaabbbb-0000-cccc-1111-dddd2222eeee<AttributeValue>
令牌生存期 nbfexp 定义令牌保持有效状态的时间间隔。 服务验证令牌的当前日期是否在令牌生存期内,如果不是,则拒绝令牌。 考虑到 Microsoft Entra ID 与服务之间可能存在时钟时间差异(“时间偏差”),服务可能允许超出令牌生存期最多五分钟。 <Conditions
NotBefore="2013-03-18T21:32:51.261Z"
NotOnOrAfter="2013-03-18T22:32:51.261Z"
>

示例 SAML 令牌

这是典型 SAML 令牌的一个示例。

<?xml version="1.0" encoding="UTF-8"?>
<t:RequestSecurityTokenResponse xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
    <t:Lifetime>
        <wsu:Created xmlns:wsu="https://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2014-12-24T05:15:47.060Z</wsu:Created>
        <wsu:Expires xmlns:wsu="https://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2014-12-24T06:15:47.060Z</wsu:Expires>
    </t:Lifetime>
    <wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
        <EndpointReference xmlns="https://www.w3.org/2005/08/addressing">
            <Address>https://contoso.onmicrosoft.com/MyWebApp</Address>
        </EndpointReference>
    </wsp:AppliesTo>
    <t:RequestedSecurityToken>
        <Assertion xmlns="urn:oasis:names:tc:SAML:2.0:assertion" ID="_3ef08993-846b-41de-99df-b7f3ff77671b" IssueInstant="2014-12-24T05:20:47.060Z" Version="2.0">
            <Issuer>https://sts.windows.net/aaaabbbb-0000-cccc-1111-dddd2222eeee/</Issuer>
            <ds:Signature xmlns:ds="https://www.w3.org/2000/09/xmldsig#">
                <ds:SignedInfo>
                    <ds:CanonicalizationMethod Algorithm="https://www.w3.org/2001/10/xml-exc-c14n#" />
                    <ds:SignatureMethod Algorithm="https://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
                    <ds:Reference URI="#_3ef08993-846b-41de-99df-b7f3ff77671b">
                        <ds:Transforms>
                            <ds:Transform Algorithm="https://www.w3.org/2000/09/xmldsig#enveloped-signature" />
                            <ds:Transform Algorithm="https://www.w3.org/2001/10/xml-exc-c14n#" />
                        </ds:Transforms>
                        <ds:DigestMethod Algorithm="https://www.w3.org/2001/04/xmlenc#sha256" />
                        <ds:DigestValue>cV1J580U1pD24hEyGuAxrbtgROVyghCqI32UkER/nDY=</ds:DigestValue>
                    </ds:Reference>
                </ds:SignedInfo>
                <ds:SignatureValue>j+zPf6mti8Rq4Kyw2NU2nnu0pb{lots of characters}ut93UTyTAIGOs5fvP9ZfK2vNeMVJW7Xg==</ds:SignatureValue>
                <KeyInfo xmlns="https://www.w3.org/2000/09/xmldsig#">
                    <X509Data>
                        <X509Certificate>MIIDPjCCAabcAwIBAgIQsRiM0jheFZhKk49YD0SK1TAJBgUrDg{lots of characters}OBcXWLAIarZ</X509Certificate>
                    </X509Data>
                </KeyInfo>
            </ds:Signature>
            <Subject>
                <NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">m_H3naDei2LNxUmEcWd0BZlNi_jVET1pMLR6iQSuYmo</NameID>
                <SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer" />
            </Subject>
            <Conditions NotBefore="2014-12-24T05:15:47.060Z" NotOnOrAfter="2014-12-24T06:15:47.060Z">
                <AudienceRestriction>
                    <Audience>https://contoso.onmicrosoft.com/MyWebApp</Audience>
                </AudienceRestriction>
            </Conditions>
            <AttributeStatement>
                <Attribute Name="http://schemas.microsoft.com/identity/claims/objectidentifier">
                    <AttributeValue>aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb</AttributeValue>
                </Attribute>
                <Attribute Name="http://schemas.microsoft.com/identity/claims/tenantid">
                    <AttributeValue>aaaabbbb-0000-cccc-1111-dddd2222eeee</AttributeValue>
                </Attribute>
                <Attribute Name="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name">
                    <AttributeValue>sample.admin@contoso.onmicrosoft.com</AttributeValue>
                </Attribute>
                <Attribute Name="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname">
                    <AttributeValue>Admin</AttributeValue>
                </Attribute>
                <Attribute Name="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname">
                    <AttributeValue>Sample</AttributeValue>
                </Attribute>
                <Attribute Name="http://schemas.microsoft.com/ws/2008/06/identity/claims/groups">
                    <AttributeValue>5581e43f-6096-41d4-8ffa-04e560bab39d</AttributeValue>
                    <AttributeValue>07dd8a89-bf6d-4e81-8844-230b77145381</AttributeValue>
                    <AttributeValue>0e129f4g-6b0a-4944-982d-f776000632af</AttributeValue>
                    <AttributeValue>3ee07328-52ef-4739-a89b-109708c22fb5</AttributeValue>
                    <AttributeValue>329k14b3-1851-4b94-947f-9a4dacb595f4</AttributeValue>
                    <AttributeValue>6e32c650-9b0a-4491-b429-6c60d2ca9a42</AttributeValue>
                    <AttributeValue>f3a169a7-9a58-4e8f-9d47-b70029v07424</AttributeValue>
                    <AttributeValue>8e2c86b2-b1ad-476d-9574-544d155aa6ff</AttributeValue>
                    <AttributeValue>1bf80264-ff24-4866-b22c-6212e5b9a847</AttributeValue>
                    <AttributeValue>4075f9c3-072d-4c32-b542-03e6bc678f3e</AttributeValue>
                    <AttributeValue>76f80527-f2cd-46f4-8c52-8jvd8bc749b1</AttributeValue>
                    <AttributeValue>0ba31460-44d0-42b5-b90c-47b3fcc48e35</AttributeValue>
                    <AttributeValue>edd41703-8652-4948-94a7-2d917bba7667</AttributeValue>
                </Attribute>
                <Attribute Name="http://schemas.microsoft.com/identity/claims/identityprovider">
                    <AttributeValue>https://sts.windows.net/aaaabbbb-0000-cccc-1111-dddd2222eeee/</AttributeValue>
                </Attribute>
            </AttributeStatement>
            <AuthnStatement AuthnInstant="2014-12-23T18:51:11.000Z">
                <AuthnContext>
                    <AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</AuthnContextClassRef>
                </AuthnContext>
            </AuthnStatement>
        </Assertion>
    </t:RequestedSecurityToken>
    <t:RequestedAttachedReference>
        <SecurityTokenReference xmlns="https://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:d3p1="https://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd" d3p1:TokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0">
            <KeyIdentifier ValueType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLID">_3ef08993-846b-41de-99df-b7f3ff77671b</KeyIdentifier>
        </SecurityTokenReference>
    </t:RequestedAttachedReference>
    <t:RequestedUnattachedReference>
        <SecurityTokenReference xmlns="https://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:d3p1="https://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd" d3p1:TokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0">
            <KeyIdentifier ValueType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLID">_3ef08993-846b-41de-99df-b7f3ff77671b</KeyIdentifier>
        </SecurityTokenReference>
    </t:RequestedUnattachedReference>
    <t:TokenType>http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0</t:TokenType>
    <t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType>
    <t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey</t:KeyType>
</t:RequestSecurityTokenResponse>

后续步骤