B2C SAML 缺失声明

B2C SAML missing claims

我正在尝试使用 B2C 自定义策略将 B2C 配置为我的 SAML Idp。作为测试,我将我们的内部部署 ADFS 环境设置为 SAML RP,这似乎是 B2C 登录页面工作所必需的(B2C SAML 不支持 Idp 启动的会话)。

我一直在按照 https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-get-started-custom and https://github.com/Azure-Samples/active-directory-b2c-advanced-policies/blob/master/Walkthroughs/RP-SAML.md 上的指南设置我的 B2C 环境。

我尽可能显示最终用户收到的 B2C 登录页面,但是在我将帐户凭据输入 B2C 登录页面后,我使用 SAML 令牌重定向回我的 RP但是它不解析任何已配置的声明。 SAML 令牌显示以下错误:

<samlp:Status> 
<samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Responder" />
     <samlp:StatusMessage>Id:410906d7-639d-4828-b28d-22f84dfa617b ; Message: Policy &apos;B2C_1A_signup_signin_saml' in tenant ' mytenant.onmicrosoft.com'' specifies the claim 'sub' for the SubjectNamingInfo, but the claim is either not present or is null.</samlp:StatusMessage> 
<IsPolicySpecificError>true</IsPolicySpecificError> 
</samlp:Status>

我的SignUpOrSigninSaml.xmlRP配置如下:

<RelyingParty>
  <DefaultUserJourney ReferenceId="SignUpOrSignInSaml"/>
    <TechnicalProfile Id="PolicyProfile">
      <DisplayName>PolicyProfile</DisplayName>
      <Protocol Name="SAML2" />
        <Metadata>
          <Item Key="PartnerEntity">https://adfs-test.mycorporation.com.au/FederationMetadata/2007-06/FederationMetadata.xml</Item>
          <Item Key="KeyEncryptionMethod">Rsa15</Item>
          <Item Key="DataEncryptionMethod">Aes256</Item>
          <Item Key="XmlSignatureAlgorithm">Sha256</Item>
        </Metadata>

    <OutputClaims>
      <OutputClaim ClaimTypeReferenceId="displayName" />
      <OutputClaim ClaimTypeReferenceId="givenName" />
      <OutputClaim ClaimTypeReferenceId="surname" />
    </OutputClaims>
    <!-- The ClaimType in the SubjectNamingInfo element below is a reference to the name of the claim added to the claims bag used by the token minting process.
    This name is determined in the following order. If no PartnerClaimType is specified on the output claim above, then the DefaultPartnerClaimType for the protocol specified in the claims schema if one exists is used, otherwise the ClaimTypeReferenceId in the output claim is used.

    For the SubjectNamingInfo below we use the DefaultPartnerClaimType of http://schemas.microsoft.com/identity/claims/objectidentifier, since the output claim does not specify a PartnerClaimType. -->
    <!-- <SubjectNamingInfo ClaimType="http://schemas.microsoft.com/identity/claims/objectidentifier" Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" ExcludeAsClaim="true"/> -->
    <SubjectNamingInfo ClaimType="sub" />
</TechnicalProfile>
</RelyingParty>

我为 "SubjectNamingInfo" 尝试了几种不同的配置,例如:

<SubjectNamingInfo ClaimType="http://schemas.microsoft.com/identity/claims/objectidentifier" Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" ExcludeAsClaim="true"/>

<SubjectNamingInfo ClaimType="sub" />

<SubjectNamingInfo ClaimType="name" />

但它们都产生相同的错误。

我相信一旦 SubjectNamingInfo 问题得到解决,配置的 OutputClaims 就会显示。

有人知道我该如何解决这个问题,以便我能够在令牌中看到我的用户帐户的声明吗?

---编辑---

我试图添加 "sub" 作为输出声明,但是由于它没有在基本文件中定义,B2C 不允许它。或者,我尝试将主题命名信息更改为已定义为输出声明的声明

<SubjectNamingInfo ClaimType="givenName" />

但是我似乎仍然遇到同样的错误:

<samlp:Status> 
<samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Responder" /> 
<samlp:StatusMessage>Id:a3fe7ab0-4483-45b6-93f8-e75b539a3aea ; Message: The relying party technical profile of policy &apos;mytenant.onmicrosoft.com' in tenant 'B2C_1A_signup_signin_saml' specifies the claim type 'givenName' as the subject naming info claim, but the claim is not present or is null.</samlp:StatusMessage> 
<IsPolicySpecificError>true</IsPolicySpecificError>

使用 sub 声明作为 SAML 断言的 <saml:Subject><saml:NameID> 元素并不常见。

建议使用objectId声明如下。

1) 确保 objectId 声明与 SAML2 协议的合作伙伴声明一起声明:

<ClaimType Id="objectId">
  <DisplayName>Object Identifier</DisplayName>
  <DataType>string</DataType>
  <DefaultPartnerClaimTypes>
    <Protocol Name="OAuth2" PartnerClaimType="oid" />
    <Protocol Name="OpenIdConnect" PartnerClaimType="oid" />
    <Protocol Name="SAML2" PartnerClaimType="http://schemas.microsoft.com/identity/claims/objectidentifier" />
  </DefaultPartnerClaimTypes>
</ClaimType>

2) 将 objectId 声明添加到依赖方技术配置文件的 <OutputClaims /> 集合并设置 SubjectNamingInfo 元素:

<RelyingParty>
  <TechnicalProfile Id="PolicyProfile">
    <OutputClaims>
      <OutputClaim ClaimTypeReferenceId="objectId" />
      <OutputClaim ClaimTypeReferenceId="displayName" />
      <OutputClaim ClaimTypeReferenceId="givenName" />
      <OutputClaim ClaimTypeReferenceId="surname" />
    </OutputClaims>
    <SubjectNamingInfo ClaimType="http://schemas.microsoft.com/identity/claims/objectidentifier" Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" ExcludeAsClaim="true"/>
  </TechnicalProfile>
</RelyingParty>

有关 SubjectNamingInfo

的更多信息

SubjectNamingInfo 元素的 ClaimType 属性引用了必须声明为技术配置文件输出声明的声明类型。

此声明类型按名称引用,优先级如下:

1) 如果为 OutputClaim 元素指定了 PartnerClaimType 属性,则 ClaimType SubjectNamingInfo 元素的属性必须设置为此 OutputClaim 元素的 ClaimTypeReferenceId 属性:

<RelyingParty>
  <TechnicalProfile Id="PolicyProfile">
    <OutputClaims>
      <OutputClaim ClaimTypeReferenceId="objectId" PartnerClaimType="http://schemas.microsoft.com/identity/claims/objectidentifier" />
      ...
    </OutputClaims>
    <SubjectNamingInfo ClaimType="objectId" Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" ExcludeAsClaim="true"/>
  </TechnicalProfile>
</RelyingParty>

2) 如果未指定 PartnerClaimType 元素的 OutputClaim 属性,则 ClaimType 元素的 SubjectNamingInfo 属性必须设置为 DefaultPartnerClaimType 元素的 ClaimType 属性此 OutputClaim 元素的 ClaimTypeReferenceId 属性引用:

<ClaimType Id="objectId">
  <DefaultPartnerClaimTypes>
    <Protocol Name="SAML2" PartnerClaimType="http://schemas.microsoft.com/identity/claims/objectidentifier" />
  </DefaultPartnerClaimTypes>
</ClaimType>

<RelyingParty>
  <TechnicalProfile Id="PolicyProfile">
    <OutputClaims>
      <OutputClaim ClaimTypeReferenceId="objectId" />
      ...
    </OutputClaims>
    <SubjectNamingInfo ClaimType="http://schemas.microsoft.com/identity/claims/objectidentifier" Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" ExcludeAsClaim="true"/>
  </TechnicalProfile>
</RelyingParty>