How do I read the NameID element as a claim in a B2C TechnicalProfile for a SAML2 identity provider?

大城市里の小女人 提交于 2019-12-06 00:10:19

The solution to use assertionSubjectName is definitely correct. In fact, MSFT updated their main documentation page on Dec 20th 2018 to add further information: Define a SAML Technical Profile. That being said - I wanted to add one more note that may help others who come across this behavior. It appears that Azure will NOT map the NameID to your output claim if the NameID element has a "NameQualifier" attribute.

Example - this will map to your output claim:

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

This will NOT map to your output claim:

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

Hopefully this will be helpful to anyone who has run into a situation where "assertionSubjectName" does not appear to work. That being said - it seems that this behavior is not all that desirable and I have reached out to MSFT to find out if this is WAD or not.

For the SAML2 protocol, the value of the NameID element can be accessed by using a PartnerClaimType with the value "assertionSubjectName". This is mentioned in the "Specifying a technical profile for a SAML 2.0 claims provider" section of Features part 6 in the Advanced Policies Git repo.

For example, to map the NameID from the SAML Assertion to the "employeeId" claim, set its PartnerClaimType to "assertionSubjectName" in the OutputClaim claim element.

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

Another example can be found in Specifying a technical profile for a SAML 2 excerpt from documentation.docx.

Edit

Per Adam C's answer, this is now documented at Define a SAML technical profile in an Azure Active Directory B2C custom policy. He also notes that B2C will not map NameID to your output claim if the NameID element has a "NameQualifier" attribute.

In my case, I was trying to extract the NameID from a SAML response where the NameID element had an SPNameQualifier attribute. Using assertionSubjectName was not working.

However, what did work was using the SPNameQualifier attribute value.

For example, suppose your SAML response looks like

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

To extract the NameID value you can set your claim mapping as

<OutputClaims>
  <!-- Other claims -->
  <OutputClaim ClaimTypeReferenceId="employeeId" PartnerClaimType="https://bar.com/realms/foo" />
</OutputClaims>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!