如何将 NameID 元素读取为 SAML2 身份提供程序的 B2C 技术配置文件中的声明?



我遵循了在Azure Active Directory B2C中使用自定义策略设置使用Salesforce SAML提供程序登录中的示例 并能够成功地将 Salesforce SSO SSO 转换为 Azure B2C。但是,我也想检索 SAML 断言中的 NameID 元素作为声明。这可能吗?

例如,假设发布到 B2C 的断言使用者终结点的传入 SAML 2.0 断言看起来 类似这样的东西简化了 XML。

<saml:Assertion>
<saml:Issuer>https://mytestinstance-dev-ed.my.salesforce.com</saml:Issuer>
<saml:Subject>
<saml:NameID>emp99999</saml:NameID>
</saml:Subject>
<saml:AuthnStatement AuthnInstant="2018-10-04T16:56:44.192Z">
<saml:AuthnContext>
<saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified</saml:AuthnContextClassRef>
</saml:AuthnContext>
</saml:AuthnStatement>
<saml:AttributeStatement>
<saml:Attribute Name="userId">
<saml:AttributeValue>009f90000099zzz</saml:AttributeValue>
</saml:Attribute>
<saml:Attribute Name="username">
<saml:AttributeValue>user000@example.com</saml:AttributeValue>
</saml:Attribute>
<saml:Attribute Name="email">
<saml:AttributeValue>user000@example.com</saml:AttributeValue>
</saml:Attribute>
<saml:Attribute Name="">
<saml:AttributeValue>false</saml:AttributeValue>
</saml:Attribute>
</saml:AttributeStatement>
</saml:Assertion>

技术配置文件允许您通过引用其 PartnerClaim中的名称在 OutputClaim 元素中键入。例如,在下面的技术概况中,socialIdpUserId 声明是 设置为 SAML 断言中的 userId 属性值"009f90000099zzz"。我想要的是 是名为 employeeId 的声明,设置为"emp99999",即 NameID 元素的值。

<TechnicalProfile Id="salesforce">
<DisplayName>Salesforce</DisplayName>
<Description>Login with your Salesforce account</Description>
<Protocol Name="SAML2"/>
<Metadata>
<Item Key="RequestsSigned">false</Item>
<Item Key="WantsEncryptedAssertions">false</Item>
<Item Key="WantsSignedAssertions">false</Item>
<Item Key="PartnerEntity">https://mytestinstance-dev-ed.my.salesforce.com/.well-known/samlidp/TestB2C.xml</Item>
</Metadata>
<!-- <CryptographicKeys>  -->
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="socialIdpUserId" PartnerClaimType="userId"/>
<OutputClaim ClaimTypeReferenceId="email" PartnerClaimType="email"/>
<OutputClaim ClaimTypeReferenceId="displayName" PartnerClaimType="username"/>
<OutputClaim ClaimTypeReferenceId="authenticationSource" DefaultValue="socialIdpAuthentication"/>
<OutputClaim ClaimTypeReferenceId="identityProvider" DefaultValue="SAMLIdp" />
<!-- We want the Subject/NameID value as a custom employeeId claim. URI reference doesn't work. -->
<OutputClaim ClaimTypeReferenceId="employeeId" 
PartnerClaimType="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier" />
</OutputClaims>
<!--<OutputClaimsTransformations> -->
<UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop"/>
</TechnicalProfile>

我尝试使用PartnerClaimType值,如"NameID","NameIdentifier",以及众所周知的NameIdentifierURI。 这些似乎都不起作用。

我还看到了一些关于使用SubjectNamingInfo元素的引用,并对其进行了实验, 但这似乎只与定义发送给 RelyingParty 的令牌有关 而不是从从 IDP 收到的令牌中读取索赔。

另外,其他断言元素呢?例如,根据 IDP 如何使用它, 我可以看到需要读取 AuthnContextClassRef 值来决定是否 发出 MFA 质询。

使用 assertionSubjectName 的解决方案绝对是正确的。事实上,MSFT 于 2018 年 12 月 20 日更新了其主要文档页面,以添加更多信息:定义 SAML 技术配置文件。话虽如此 - 我想再添加一个注释,可能会帮助遇到这种行为的其他人。如果 NameID 元素具有"名称限定符"属性,则 Azure 似乎不会将 NameID 映射到输出声明。

示例 - 这将映射到您的输出声明:

<Subject>
<NameID>foo@bar.com</NameID>

这不会映射到您的输出声明:

<Subject>
<NameID NameQualifier="https://bar.com/realms/foo">foo@bar.com</NameID>

希望这对遇到"assertionSubjectName"似乎不起作用的情况的任何人有所帮助。话虽如此 - 似乎这种行为并不是那么可取,我已经联系了 MSFT 以了解这是否是 WAD。

对于 SAML2 协议,可以使用值为"assertionSubjectName">PartnerClaimType访问 NameID 元素的值。 "为 SAML 2.0 声明提供程序指定技术配置文件"一节中提到了这一点 功能第 6 部分 在高级策略 Git 存储库中。

例如,要将 NameID 从 SAML 断言映射到"employeeId"声明,请将其PartnerClaimType设置为"断言主题名称" 在OutputClaim声明元素中。

<OutputClaims>
<!-- Other claims -->
<OutputClaim ClaimTypeReferenceId="employeeId" 
PartnerClaimType="assertionSubjectName" />
</OutputClaims>

另一个例子可以在 为文档.docx中的 SAML 2 摘录指定技术配置文件。

编辑

根据Adam C的回答,这现在记录在 在 Azure Active Directory B2C 自定义策略中定义 SAML 技术配置文件。他还指出,如果 NameID 元素具有"NameQualifier"属性,则 B2C 不会将 NameID 映射到输出声明。

就我而言,我试图从 SAML 响应中提取 NameID,其中 NameID 元素具有SPNameQualifier属性。使用assertionSubjectName不起作用。

但是,起作用的是使用SPNameQualifier属性值

例如,假设您的 SAML 响应如下所示

<saml:Subject>
<saml:NameID SPNameQualifier="https://bar.com/realms/foo">emp99999</saml:NameID>
</saml:Subject>

若要提取 NameID 值,可以将声明映射设置为

<OutputClaims>
<!-- Other claims -->
<OutputClaim ClaimTypeReferenceId="employeeId" PartnerClaimType="https://bar.com/realms/foo" />
</OutputClaims>

相关内容

最新更新