通过 AD Graph API 更新 B2C 自定义属性字符串集合

spo*_*ahn 5 azure-ad-graph-api azure-ad-b2c

我可以定义数据类型为 的自定义属性stringCollection并通过 Azure AD Graph API 更新它吗?我的实验失败了:

请求正文包含指定内容类型和编码的意外字符/内容


自定义属性定义

<ClaimType Id="extension_array_test">
    <DisplayName>Array Test</DisplayName>
    <DataType>stringCollection</DataType>
    <UserHelpText>Array Test in Token</UserHelpText>
</ClaimType>  
Run Code Online (Sandbox Code Playgroud)

使用Graph API 示例客户端

{
    "extension_[my-guid]_array_test": ["value 1", "value 2"]
}

Error Calling the Graph API:
{
  "odata.error": {
    "code": "Request_BadRequest",
    "message": {
      "lang": "en",
      "value": "The request body contains unexpected characters/content for the specified content type and encoding."
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

nyo*_*ung 2

您提供的文档中的第二个注释指出扩展属性当前仅支持字符串数据类型。

作为替代方案,您可以将数据存储为转义 JSON,如下所示:

"extension_{GUID}_JsonAttribute": "{\"Item1\":\"Test\",\"Item2\":\"Data\"}"
Run Code Online (Sandbox Code Playgroud)

  • 请注意,当前在存储(JSON 中)字符串时限制为 256 个字符:[文档](https://learn.microsoft.com/en-us/previous-versions/azure/ad/graph/howto/azure- ad-graph-api-directory-schema-extensions#extension-data-types--) (2认同)