SAML 令牌声明参考

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

SAML 令牌中的声明

名称 等效的 JWT 声明 DESCRIPTION 示例:
观众 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 安全组成员身份,“全部”的值将同时包括安全组和Microsoft 365 通讯组列表。

注释
如果用户进入的组数超出限制(对于 SAML 为 150,对于 JWT 为 200),则会添加超额声明,该声明指向包含用户组列表的 Graph 终结点的声明源。
<Attribute Name="http://schemas.microsoft.com/ws/2008/06/identity/claims/groups">
<AttributeValueaaaaaaaa-0000-1111-2222-bbbbbbbbbbbb</AttributeValue>
组超额指示器 groups:src1 对于长度限制但对于令牌来说仍然太大的令牌请求,将包含指向用户的完整组列表的链接。 对于 SAML,此声明将添加为代替声明的新声明 groups

注释
Azure AD 图形 API 正在替换为Microsoft图形 API。 若要了解有关等效终结点的详细信息,请参阅 用户: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>
对象标识符 oid 包含Microsoft Entra ID 中对象的唯一标识符。 此值固定不变,无法重新分配或重复使用。 使用对象 ID 标识查询中的对象,以Microsoft Entra ID。 <Attribute Name="http://schemas.microsoft.com/identity/claims/objectidentifier">
<AttributeValue>bbbbbbbb-1111-2222-3333-cccccccccccc<AttributeValue>
角色 roles 表示主题通过组成员身份直接或间接授予的所有应用程序角色,并可用于强制实施基于角色的访问控制。 通过应用程序清单的属性,按应用程序定义 appRoles 应用程序角色。 value每个应用程序角色的属性是角色声明中显示的值。 <Attribute Name="http://schemas.microsoft.com/ws/2008/06/identity/claims/role">
使用者 sub 标识令牌断言信息的主体,例如应用程序的用户。 主题始终存在于MICROSOFT Entra ID 问题的 SAML 令牌中。 根据 NameID 格式,此值 可用于 标识常规用途授权系统中的主题(请参阅 使用电子邮件地址进行授权时的风险)。
SubjectConfirmation 不是声明。 它描述如何验证令牌的主题。 Bearer 指示使用者由其拥有令牌进行确认。
<Subject>
<NameID>S40rgb3XjhFTv6EQTETkEzcgVmToHKRkZUIsJlmLdVc</NameID>
<SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer" />
</Subject>
租户 ID tid 一个不可变的非可重用标识符,用于标识颁发令牌的目录租户。 可以使用此值访问多租户应用程序中特定于租户的目录资源。 例如,可以使用此值标识调用图形 API 中的租户。 <Attribute Name="http://schemas.microsoft.com/identity/claims/tenantid">
<AttributeValue>aaaabbbb-0000-cccc-1111-dddd2222eeee<AttributeValue>
令牌生存期 nbfexp 定义令牌有效的时间间隔。 验证令牌的服务应验证当前日期是否在令牌生存期内,否则应拒绝令牌。 服务可能允许超过令牌生存期范围 5 分钟,以考虑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="_aaaaaaaa-0b0b-1c1c-2d2d-333333333333" 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="#_aaaaaaaa-0b0b-1c1c-2d2d-333333333333">
                        <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>E3fH4iJ5kL6mN7oP8qR9sT0uV1wX2y/nDY=</ds:DigestValue>
                    </ds:Reference>
                </ds:SignedInfo>
                <ds:SignatureValue>aB1cD2eF3gH4i...J5kL6-mN7oP8qR==</ds:SignatureValue>
                <KeyInfo xmlns="https://www.w3.org/2000/09/xmldsig#">
                    <X509Data>
                        <X509Certificate>C2dE3fH4iJ5kL6mN7oP8qR9sT0uV1w</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">_aaaaaaaa-0b0b-1c1c-2d2d-333333333333</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">_aaaaaaaa-0b0b-1c1c-2d2d-333333333333</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>

后续步骤