Azure AD B2C:无法将公司名称公开为令牌

2023-12-21

我使用 Azure AD B2C 和自定义策略来管理用户并提供登录体验。我注意到有一个内置(不是自定义扩展)属性名称companyName,我正在使用用户的公司信息进行更新。我可以通过图形 API 更新此字段值并分别检索它。更新此值后,我尝试将其包含在声明中并发送到客户端应用程序,但是我遇到了问题。我已确保在 TrustFrameworkBase 政策中包含如下声明

<ClaimType Id="companyName">
        <DisplayName>companyName</DisplayName>
        <DataType>string</DataType>
</ClaimType>

此外,我还更新了 AAD-UserReadUsingObjectId 技术配置文件,该配置文件负责进行图形调用(身份验证成功后)并获取所有用户属性。这是 AAD-UserReadUsingObjectId 技术配置文件的定义

<TechnicalProfile Id="AAD-UserReadUsingObjectId">
          <Metadata>
            <Item Key="Operation">Read</Item>
            <Item Key="RaiseErrorIfClaimsPrincipalDoesNotExist">true</Item>
          </Metadata>
          <IncludeInSso>false</IncludeInSso>
          <InputClaims>
            <InputClaim ClaimTypeReferenceId="objectId" Required="true" />
          </InputClaims>
          <OutputClaims>
            <!-- Optional claims -->
            <OutputClaim ClaimTypeReferenceId="signInNames.emailAddress" />
            <OutputClaim ClaimTypeReferenceId="displayName" />
            <OutputClaim ClaimTypeReferenceId="mobile" />
            <OutputClaim ClaimTypeReferenceId="country" />
            <OutputClaim ClaimTypeReferenceId="postalCode" />
            <OutputClaim ClaimTypeReferenceId="state" />
            <OutputClaim ClaimTypeReferenceId="company" />
            <OutputClaim ClaimTypeReferenceId="companyName" />
            <OutputClaim ClaimTypeReferenceId="surname" />
            <OutputClaim ClaimTypeReferenceId="givenName" />
            <OutputClaim ClaimTypeReferenceId="email" />
            <OutputClaim ClaimTypeReferenceId="objectId" />
            <!--Adding custom attribute start-->
            <OutputClaim ClaimTypeReferenceId="otherMails" />
            <OutputClaim ClaimTypeReferenceId="extension_UserGuid" />
            <OutputClaim ClaimTypeReferenceId="extension_StatusFlag" />
            <OutputClaim ClaimTypeReferenceId="extension_EZUserName" />
            <OutputClaim ClaimTypeReferenceId="CurrentTime" />
            <!--Adding custom attribute end-->
          </OutputClaims>
          <OutputClaimsTransformations>
            <OutputClaimsTransformation ReferenceId="GetSystemDateTime" />
          </OutputClaimsTransformations>
          <IncludeTechnicalProfile ReferenceId="AAD-Common" />
</TechnicalProfile>

最后,我将此 companyName 声明包含在用户旅程输出声明中。

即使完成所有这些操作后,我注意到 companyName 声明并不在 azure AD B2C 返回的令牌内。 为了进一步排除故障,我为我的策略启用了应用程序洞察,并且观察到了一个奇怪的行为。

当 Azure AD B2C 在执行时进行图形调用时AAD-UserReadUsingObjectId技术概况它形成一个类似于下面的查询https://graph.windows.net/f17d6207-7c3a-4d29-b802-ad5429b2a8d8/users/77669822-8034-4666-9800-8b614c0ccbfc?api-version=1.6-integrationOnly https://graph.windows.net/f17d6207-7c3a-4d29-b802-ad5429b2a8d8/users/77669822-8034-4666-9800-8b614c0ccbfc?api-version=1.6-integrationOnly并且此图形 api 调用的输出根本不包含 companyName 属性,但是当我使用我的应用程序 id 和 Secrete 进行类似查询的图形 api 调用时,我确实在响应中看到了 companyName。 Azure AD B2C 调用的查询与我调用 api url 中的最后一部分的查询的唯一区别。 Azure AD B2C 有-仅集成最后我没有。我不确定为什么当 Azure AD B2C 执行与我执行时图形 API 调用响应不同。

我可以通过简单地添加一个新的自定义扩展字段并使用它而不是 companyName 来解决这个问题,但我的观点是为什么我应该在开箱即用时创建一个自定义属性,更重要的是它需要我修复大约 100 万个现有用户。 有没有人遇到过此类问题。任何帮助都会很棒!

提前致谢!


CompanyName 是 O365 内置属性。如您所见,B2C 在后端使用仅集成 api 版本进行自己的调用。唯一的解决方案是使用扩展属性。用于修补用户的脚本可以在大约 12 小时内修复 100 万用户。 使用自定义策略时,请坚持使用您自己的自定义属性,尝试使用默认属性名称并没有真正的优势,只是有时您会发现缺点。自定义策略只需要您将属性名称声明为extension_,它的工作方式就像任何内置属性一样。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Azure AD B2C:无法将公司名称公开为令牌 的相关文章

随机推荐