当我使用自定义策略时,如何让 Azure AD B2C 的内置声明在令牌中返回?

How do I get Azure AD B2C's built-in claims to be returned in the token when I'm using a custom policy?

我已经使用内置的 SignUpOrSignIn 政策一段时间了,但我现在要转向自定义政策。

当我设置内置策略时,我可以从内置应用程序声明列表中进行选择(如 displayNamejobTitle),以及 select当用户登录时,我希望在令牌中返回哪些。

现在我正在设置自定义策略我想做同样的事情,但我无法让它工作。

到目前为止,在 TrustFrameworkBase 中我添加了一个 ClaimType of jobTitle:

<ClaimType Id="jobTitle">
    <DisplayName>Job Title</DisplayName>
    <DataType>string</DataType>
    <UserHelpText>Job title.</UserHelpText>
</ClaimType>

我已将以下 OutputClaim 添加到 ID login-NonInteractiveTechnicalProfile

<OutputClaim ClaimTypeReferenceId="jobTitle" PartnerClaimType="jobTitle" />

并且我已将以下 OutputClaim 添加到 ID SelfAsserted-LocalAccountSignin-EmailTechnicalProfile

<OutputClaim ClaimTypeReferenceId="jobTitle" />

但是 jobTitle 声明没有通过令牌中的其他声明。我对 given_name 做了同样的事情,这确实有效。如果我将第一个 OutputClaim 更改为:

<OutputClaim ClaimTypeReferenceId="jobTitle" PartnerClaimType="given_name" />

然后 jobTitle 声明 确实 通过了,但具有 given_name 声明的价值。这意味着我只是使用了错误的 PartnerClaimType 但似乎在任何地方都没有它们的列表。

当用户使用他们的本地 B2C 帐户登录时,如何让内置职位属性作为令牌中的声明返回?

如果您只想读取用户的 jobTitle 声明(或其他声明),然后在令牌中发布它(或它们),那么您必须:

1) 声明 jobTitle 声明:

<ClaimType Id="jobTitle">
  <DisplayName>Job Title</DisplayName>
  <DataType>string</DataType>
  <DefaultPartnerClaimTypes>
    <Protocol Name="OAuth2" PartnerClaimType="job_title" />
    <Protocol Name="OpenIdConnect" PartnerClaimType="job_title" />
  </DefaultPartnerClaimTypes>
</ClaimType>

2) 将 jobTitle 声明作为输出声明添加到 AAD-UserReadUsingObjectId 技术配置文件中:

<TechnicalProfile Id="AAD-UserReadUsingObjectId">
  ...
  <OutputClaims>
    ...
    <OutputClaim ClaimTypeReferenceId="jobTitle" />
  </OutputClaims>
  ...
</TechnicalProfile>

3) 添加 jobTitle 声明作为依赖方技术配置文件的输出声明:

<RelyingParty>
  ...
  <TechnicalProfile Id="PolicyProfile">
    ...
    <OutputClaims>
      ...
      <OutputClaim ClaimTypeReferenceId="jobTitle" />
    </OutputClaims>
    ...
  </TechnicalProfile>
</RelyingParty>