关于 Azure AD B2C 中的自定义属性。 有没有办法从 Azure AD B2C 中 ID token 中包含的自定义属性中删除“扩展名”前缀?
在 Azure AD B2C 中定义自定义属性时, 该属性在 ID token 参数中将具有前缀“extension”。有没有办法删除“扩展名”前缀?
例如,我想将“extension_sampledata”获取为“sampledata”
我无法将其从 Azure AD B2C 用户流中删除,因此我正在尝试自定义策略。
最佳答案
我认为您无法在用户流中更改这一点,但您绝对可以使用自定义策略。
选项 1 - RelyingParty 定义
在您的 RelyingParty 中定义中,您可以指定 PartnerClaimType
,这是 B2C 将用于 token 中声明的名称。
例如,RelyingParty
定义:
<RelyingParty>
<DefaultUserJourney ReferenceId="SignIn"/>
<UserJourneyBehaviors>
<SingleSignOn Scope="Tenant" />
</UserJourneyBehaviors>
<TechnicalProfile Id="PolicyProfile">
<DisplayName>OpenIdConnectProfile</DisplayName>
<Protocol Name="OpenIdConnect"/>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="objectId" PartnerClaimType="sub" />
<OutputClaim ClaimTypeReferenceId="displayName" />
<OutputClaim ClaimTypeReferenceId="extension_sampledata" PartnerClaimType="sampledata" />
</OutputClaims>
<SubjectNamingInfo ClaimType="sub" />
</TechnicalProfile>
</RelyingParty>
将生成一个包含以下声明的 token (除了 standard claims ):
{
"sub": "93575208-fd44-46fe-bafd-3156565027b3",
"displayName": "Test User",
"sampledata": "<Your data here>"
}
选项 2 - ClaimType 定义
或者,您可以在 ClaimType 中指定相同的内容定义本身:
<ClaimType Id="extension_sampledata">
<DisplayName>Sample Data</DisplayName>
<DataType>string</DataType>
<DefaultPartnerClaimTypes>
<Protocol Name="OAuth2" PartnerClaimType="sampledata" />
<Protocol Name="OpenIdConnect" PartnerClaimType="sampledata" />
</DefaultPartnerClaimTypes>
</ClaimType>
然后根据协议(protocol)自动应用适当的 PartnerClaimType
。
例如,RelyingParty
定义:
<RelyingParty>
<DefaultUserJourney ReferenceId="SignIn"/>
<UserJourneyBehaviors>
<SingleSignOn Scope="Tenant" />
</UserJourneyBehaviors>
<TechnicalProfile Id="PolicyProfile">
<DisplayName>OpenIdConnectProfile</DisplayName>
<Protocol Name="OpenIdConnect"/>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="objectId" PartnerClaimType="sub" />
<OutputClaim ClaimTypeReferenceId="displayName" />
<OutputClaim ClaimTypeReferenceId="extension_sampledata" />
</OutputClaims>
<SubjectNamingInfo ClaimType="sub" />
</TechnicalProfile>
</RelyingParty>
仍会生成包含以下声明的 token (除了 standard claims ):
{
"sub": "93575208-fd44-46fe-bafd-3156565027b3",
"displayName": "Test User",
"sampledata": "<Your data here>"
}
关于azure - 有没有办法从 Azure AD B2C 中的 ID token 中包含的自定义属性中删除 "extension"前缀?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76630113/