我正在从自定义策略调用 REST API。 我在请求正文中发送 JSON 数据,示例 JSON 数据为“
我有点困惑如何从我的自定义政策中发送以下 JSON(地址和联系人)作为输入声明。
{
"firstName": "sampleuser",
"lastName": "qa",
"addresses": [
{
"countryCode": "IN"
}
],
"contacts": {
"email": {
"address": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ff8c9e928f939a8a8c9a8d8e9ebf929e969396919e8b908dd19c9092" rel="noreferrer noopener nofollow">[email protected]</a>"
}
}
}
最佳答案
B2C 只能从自己的声明类型原语构建 JSON。分别是 int、boolean、datetime、string、stringCollection。
例如,通过在 REST API 技术配置文件中输出这些声明:
<OutputClaim ClaimTypeReferenceId="firstName" />
<OutputClaim ClaimTypeReferenceId="lastName" />
<OutputClaim ClaimTypeReferenceId="addresses" />
有了这些定义:
<ClaimType Id="firstName">
<DisplayName>firstName</DisplayName>
<DataType>string</DataType>
</ClaimType>
<ClaimType Id="lastName">
<DisplayName>lastName</DisplayName>
<DataType>string</DataType>
</ClaimType>
<ClaimType Id="addresses">
<DisplayName>addresses</DisplayName>
<DataType>stringCollection</DataType>
</ClaimType>
API 生成的 JSON 有效负载将为
{
"firstName": "sampleuser",
"lastName": "qa",
"addresses": "X, Y, Z",
}
由于我们不对 json 对象本身进行建模,因此我们无法构建如下 JSON 有效负载:
"addresses": [
{
"countryCode": "IN"
}
],
"contacts": {
"email": {
"address": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6112000c110d04141204131000210c00080d080f00150e134f020e0c" rel="noreferrer noopener nofollow">[email protected]</a>"
}
}
根据您从用户或后端系统获取此信息的方式,此 JSON 声明转换可能有助于将数据拆分为字符串/字符串集合以将数据发送到 API。
https://learn.microsoft.com/en-us/azure/active-directory-b2c/json-transformations
https://learn.microsoft.com/en-us/azure/active-directory-b2c/stringcollection-transformations
关于azure - 如何将 JSON 对象数组作为自定义策略中的输入声明传递给 REST API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57285087/