You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Azure B2C技术配置文件中保存API返回的字符串列表到OutputClaim

在Azure B2C中保存API返回的字符串列表到OutputClaim

你的API返回根级字符串数组格式:

["Some string", "Some other string"]

要把整个响应保存到OutputClaim,按以下步骤配置:

1. 定义对应的Claim类型

先在策略的<ClaimsSchema>节点中声明用于存储响应的Claim,分两种场景:

  • 场景1:直接存储为字符串数组(推荐,方便后续策略中使用)
<ClaimsSchema>
  <ClaimType Id="apiResponseStringList">
    <DisplayName>API返回的字符串列表</DisplayName>
    <DataType>stringCollection</DataType>
  </ClaimType>
</ClaimsSchema>
  • 场景2:存储为JSON格式字符串(适合需要保留原始响应格式的场景)
<ClaimsSchema>
  <ClaimType Id="apiResponseJson">
    <DisplayName>API返回的JSON字符串</DisplayName>
    <DataType>string</DataType>
  </ClaimType>
</ClaimsSchema>

2. 配置技术配置文件的OutputClaims

在调用API的技术配置文件中,通过PartnerClaimType="$"指向整个API响应体,完成映射:

对应场景1的配置

<OutputClaims>
  <OutputClaim ClaimTypeReferenceId="apiResponseStringList" PartnerClaimType="$" />
</OutputClaims>

此时Azure B2C会自动将根数组解析为stringCollection类型的Claim,直接存储每个字符串元素。

对应场景2的配置

如果要存储为JSON字符串,需先通过ClaimsTransformation将数组转为JSON,再映射:
首先添加转换规则:

<ClaimsTransformations>
  <ClaimsTransformation Id="ConvertStringCollectionToJson" TransformationMethod="ConvertStringCollectionToJson">
    <InputClaims>
      <InputClaim ClaimTypeReferenceId="apiResponseStringList" TransformationClaimType="inputClaim" />
    </InputClaims>
    <OutputClaims>
      <OutputClaim ClaimTypeReferenceId="apiResponseJson" TransformationClaimType="outputClaim" />
    </OutputClaims>
  </ClaimsTransformation>
</ClaimsTransformations>

然后在技术配置文件中先映射数组,再执行转换:

<OutputClaims>
  <OutputClaim ClaimTypeReferenceId="apiResponseStringList" PartnerClaimType="$" />
</OutputClaims>
<OutputClaimsTransformations>
  <OutputClaimsTransformation ReferenceId="ConvertStringCollectionToJson" />
</OutputClaimsTransformations>

注意事项

  • 确保技术配置文件的Protocol设置为Proprietary,并指定REST API处理程序:
<Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.RestfulProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
  • 若API响应存在跨域或认证要求,需在技术配置文件中补充对应的<Metadata>配置(比如AllowInsecureAuthInProduction、AuthenticationType等)。

内容的提问来源于stack exchange,提问作者pederOverland

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 16:05:21