【问题标题】:Return REST API response as an output claim to Azure B2C将 REST API 响应作为输出声明返回给 Azure B2C
【发布时间】:2021-12-09 08:35:49
【问题描述】:

我目前正在开发一种在 JWT 令牌中添加自定义声明的解决方案。

设置如下:

  1. Azure B2C 有一个包含多个声明提供程序的自定义策略。
  2. Azure AD 的声明提供程序配置了标准声明和我的自定义声明。
  3. 用于调用 REST API 的声明提供程序。
  4. REST API 收集配置为从 Graph API 收集自定义属性,它配置为使用“电子邮件”的输入声明来查找与用户登录相关的数据,以及使用我的名称的“输出”声明自定义声明。
  5. 在用户 SignUpSignIn 旅程中添加了一个步骤,用于在发布 JWT 令牌之前调用 REST API。

用户旅程成功运行,我可以重定向到 Azure AD 进行身份验证。我可以看到 REST API 是从 Azure 中的日志触发的,并且我获得了我的 JWT 令牌,但我没有看到包含任何声明。

当我检查 REST API 日志时,我可以看到函数运行成功,如果我在 Azure 函数中手动运行测试选项,我还可以看到成功响应,这是一个 JSON 数据数组。因此,这表明我的 REST API 正在以应有的方式工作。我还通过 PowerShell 和 Web 浏览器成功地对其进行了测试,并且在正文中得到了正确的响应。

我怀疑问题出在返回值并将其插入到自定义声明中以便它出现在我的 JWT 令牌中的过程中。

仅供参考:我正在使用的自定义声明是返回用户在 AzureAD 中是 memberOf 的安全组。

<ClaimsProvider>
<DisplayName>REST API</DisplayName>
<TechnicalProfiles>
    <TechnicalProfile Id="GetUserGroups">
  <DisplayName>Retrieves security groups assigned to the user</DisplayName>
  <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.RestfulProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
  <Metadata>
    <Item Key="ServiceUrl">https://contoso.azurewebsites.net/api/aadgroups?code=123456789QWERTYUIOP123456789QWERTYUIOP==</Item>
    <Item Key="AuthenticationType">None</Item>
    <Item Key="SendClaimsIn">Body</Item>
    <Item Key="AllowInsecureAuthInProduction">true</Item>
  </Metadata>
  <InputClaims>
    <InputClaim ClaimTypeReferenceId="email" />
  </InputClaims>
  <OutputClaims>
    <OutputClaim ClaimTypeReferenceId="restapigroups" />
  </OutputClaims>
  <UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
</TechnicalProfile>
</TechnicalProfiles>
</ClaimsProvider>

<ClaimType Id="restapigroups">
  <DisplayName>Group memberships</DisplayName>
  <DataType>stringCollection</DataType>
  <UserHelpText>This is read only for the user</UserHelpText>
  <UserInputType>Readonly</UserInputType>
</ClaimType>

<OrchestrationStep Order="11" Type="ClaimsExchange">
  <ClaimsExchanges>
    <ClaimsExchange Id="AADUserGroups" TechnicalProfileReferenceId="GetUserGroups" />
  </ClaimsExchanges>
</OrchestrationStep>

【问题讨论】:

标签: jwt azure-active-directory azure-functions azure-ad-b2c azure-ad-graph-api


【解决方案1】:

您必须配置 RelyingParty 部分以将声明输出到令牌中。看这个例子:https://docs.microsoft.com/en-us/azure/active-directory-b2c/custom-policy-rest-api-claims-exchange#add-the-claim

【讨论】:

  • 您是指 Azure AD 声明提供者的 RelyingParty 吗?输出声明添加到 REST API 和 Azure AD 声明提供程序部分(“restapigroups”)``` ``
  • 在您的 signInOrSignUp.xml 中,您将有一个以 <relyingparty> 开头的部分。这将配置您的 B2C 声明包中的哪些声明将发布到 B2C 令牌中。您必须在此处添加您的输出声明。您所描述的是您仅将索赔输出到索赔包,这还不够。
  • 我明白你现在的意思了。我确实忘记提及声明已正确添加到 SignUpOrSignIn.xml 中。我刚刚设法解决了这个问题,问题是我需要在 JSON 响应中输出的声明中添加一个引用声明类型。一旦我这样做了,索赔就会正确输出。 (PartnerClaimType="xxxxx") 感谢您的支持和帮助,我们已修复。
  • 好吧,听起来您的 API 到 B2C 声明映射不正确,因此 B2C 从未在声明包中包含声明。很高兴它解决了。
猜你喜欢
  • 2018-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-09-28
  • 1970-01-01
  • 2022-01-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多