azure - 有没有办法从 Azure AD B2C 中的 ID token 中包含的自定义属性中删除 "extension"前缀?

标签 azure azure-ad-b2c azure-ad-b2c-custom-policy

关于 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/

相关文章:

azure-ad-b2c - 上传自定义策略时出现验证错误

asp.net - Azure AD B2C - 多个子域

html - Azure AD B2C 自定义策略社交按钮顺序

azure-ad-b2c-custom-policy - B2C 自定义模拟策略给出错误

azure - 当 Web 应用程序位于 AAD 组中时,用户 '<token-identified principal>' 登录失败

amazon-web-services - IIS 上的 appConcurrentRequest 超出限制

javascript - Azure 移动服务 Node.js 上的 where 子句的过滤功能

azure-ad-b2c - 如何使用从内置和自定义策略生成的 token ?

azure - azure b2c 自定义策略未检测到北欧字符 å、ø 和 æ

xml - Azure部署: error MSB4041: The default XML namespace of the project must be the MSBuild XML namespace