azure - 如何将 JSON 对象数组作为自定义策略中的输入声明传递给 REST API

标签 azure azure-active-directory azure-ad-b2c

我正在从自定义策略调用 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/

相关文章:

azure - 我可以将单个 Azure AD B2C 租户用于 Django 应用程序的 DEV、STAGE 和 PROD 环境吗?

reactjs - 从 React 到 Web API 的 MSAL 身份验证和授权

azure - Office365 Sharepoint Social.feed AAD 授权

azure - 使用 Azure 函数从 Azure Blob 存储中删除早于 X 天的文件

.net - 从预先存在的 MVC2 应用程序启动 Windows Azure

azure - 是否可以从 Dynamics 365 在线发送用户访问 token ?

首次登录时重置密码期间出现 Azure AD B2C 错误(使用自定义策略)

c# - Botframework Web 应用程序 Azure IDX20803 : Unable to obtain configuration from: '[PII is hidden]

即使使用 MobileServiceClient - UWP 成功登录后,Azure MobileApp API 也会返回 401(未经授权)

azure - 尝试通过 Active Directory 访问 Azure Databricks API 时出现错误 403 用户未授权