我已使用 OpenIdConnect 协议将 Salesforce 作为 IdP 添加到 Azure AD B2C。而且效果很好。
在 Salesforce 的令牌中,我收到“custom_attributes”类型的声明:
"custom_attributes": {
"UserRoleName": "SC Management"
}
我现在想将该声明添加到 B2C 的政策中。 我添加一个“custom_attributes”ClaimType 并将声明作为 OutputClaim 添加到 ClaimsProvider 和 RelyingParty(见下文)。
当我测试它时,它失败了,我在跟踪中发现以下错误:
“声明类型 ID 为“custom_attributes”的声明遇到意外类型“Newtonsoft.Json.Linq.JObject”。”
如何修复此错误?
政策变更:
在 TrustFrameworkBase 中我添加:
<BuildingBlocks>
<ClaimsSchema>
=> <ClaimType Id="custom_attributes">
<DisplayName>custom_attributes</DisplayName>
<DataType>string</DataType>
<DefaultPartnerClaimTypes>
<Protocol Name="OpenIdConnect" PartnerClaimType="custom_attributes" />
</DefaultPartnerClaimTypes>
</ClaimType>
...
</ClaimsSchema>
...
</BuildingBlocks>
在 TrustFrameworkExtensions 中我添加:
<ClaimsProviders>
<ClaimsProvider>
<Domain>salesforce.com</Domain>
<DisplayName>Salesforce</DisplayName>
<TechnicalProfiles>
<TechnicalProfile Id="Salesforce-OpenIdConnect">
<OutputClaims>
=> <OutputClaim ClaimTypeReferenceId="custom_attributes" PartnerClaimType="custom_attributes" />
...
</OutputClaims>
</TechnicalProfile>
</TechnicalProfiles>
</ClaimsProvider>
</ClaimsProviders>
在 SignUpOrSignin 中我添加:
<RelyingParty>
<TechnicalProfile Id="PolicyProfile">
<DisplayName>PolicyProfile</DisplayName>
<Protocol Name="OpenIdConnect" />
<OutputClaims>
=> <OutputClaim ClaimTypeReferenceId="custom_attributes" PartnerClaimType="custom_attributes" />
...
</OutputClaims>
</TechnicalProfile Id="PolicyProfile">
</RelyingParty>
当我尝试使用仅包含文本(不是 json 格式)的声明执行完全相同的操作时,它会起作用。
我没有将“custom_attributes”声明一直传递给 RelyingParty,而是尝试创建一个 ClaimsTransform(它从令牌中选择“UserRoleName”),但这需要“custom_attributes”作为 ClaimsProvider 中的 OutputClaim - 然后我遇到同样的错误
如果您知道返回的 JSON 结构,并且它不是动态 JSON,则可以在 Salesforce-OpenIdConnect
技术配置文件的
输出声明转换中使用 从 JSON 转换获取声明。
在 REST API 调用中,您可以使用设置为 true 的元数据项
ResolveJsonPathsInJsonTokens
,然后在输出声明中将 PartnerClaimType 设置为要输出的 JSON 路径元素。例如:firstName.localized 或 data[0].to[0].email。 - 但我认为这不适用于 openIdConnect 技术配置文件协议。