Update Azure B2C custom attributes using Graph API SDK Error: quot;The request is currently not supported on the targeted entity set AdditionalData:(使用Graph API SDK更新Azure B2C自定义属性错误:目标实体集当前不支持该请求AdditionalData:)
问题描述
到目前为止,似乎还没有实现这一目标的标准方法。
经过一段时间的研究后,我想出了下面这段代码,不幸的是,它返回了一个隐晦的错误:
var user = await _graphApiService.GetUserAsync(userId); ; // gets existent user
var tempUser = new User
{
Extensions = new UserExtensionsCollectionPage
{
AdditionalData = new Dictionary<string, object>()
{
{ residentialPostcode, userToUpdate.extensionAttributes.extension_9614eff520454054b6d79fbe0c7a5491_residentialPostcode },
{ address, userToUpdate.extensionAttributes.extension_9614eff520454054b6d79fbe0c7a5491_address },
{ city, userToUpdate.extensionAttributes.extension_9614eff520454054b6d79fbe0c7a5491_city },
{ telephone, userToUpdate.extensionAttributes.extension_9614eff520454054b6d79fbe0c7a5491_Telephone },
{ termsOfUseConsentVersion, userToUpdate.extensionAttributes.extension_9614eff520454054b6d79fbe0c7a5491_termsOfUseConsentVersion },
{ dateOfBirth, userToUpdate.extensionAttributes.extension_9614eff520454054b6d79fbe0c7a5491_dateOfBirth },
{ termsOfUseConsentDateTime, userToUpdate.extensionAttributes.extension_9614eff520454054b6d79fbe0c7a5491_termsOfUseConsentDateTime },
{ haspassword, userToUpdate.extensionAttributes.extension_9614eff520454054b6d79fbe0c7a5491_haspassword }
}
}
};
user.Extensions = tempUser.Extensions;
await _graphServiceClient.Users[$"{userId}"]
.Request()
.UpdateAsync(userToUpdate);
最后一个错误:
"Error! Updating User information failed with message Code: BadRequest
Message: The request is currently not supported on the targeted entity set
Inner error:
AdditionalData:
date: 2022-01-14T21:23:33
request-id: d6c9c8b9-47fc-4aa0-bb9b-328a5b260753
client-request-id: d6c9c8b9-47fc-4aa0-bb9b-328a5b260753
ClientRequestId: d6c9c8b9-47fc-4aa0-bb9b-328a5b260753
"
--
其他信息:
My Graph API应用程序具有以下委派权限:
Directory.AccessAsUser.All
Directory.ReadWrite.All
User.Read
User.ReadWrite.All
图形SDK版本
<PackageReference Include="Microsoft.Graph" Version="4.14.0" />
推荐答案
以下解决了该错误。似乎更新B2C用户对象自定义域的正确方法是将新值直接赋给User.AdditionalData,而不是赋给User.Extensions.AdditionalData
FWIW,代码:
var additionalData = new Dictionary<string, object>();
additionalData[residentialPostcode] = userToUpdate.extensionAttributes.extension_9614eff520454054b6d79fbe0c7a5491_residentialPostcode;
additionalData[address] = userToUpdate.extensionAttributes.extension_9614eff520454054b6d79fbe0c7a5491_address;
additionalData[city] = userToUpdate.extensionAttributes.extension_9614eff520454054b6d79fbe0c7a5491_city;
additionalData[telephone] = userToUpdate.extensionAttributes.extension_9614eff520454054b6d79fbe0c7a5491_Telephone;
additionalData[termsOfUseConsentVersion] = userToUpdate.extensionAttributes.extension_9614eff520454054b6d79fbe0c7a5491_termsOfUseConsentVersion;
additionalData[termsOfUseConsentDateTime] = userToUpdate.extensionAttributes.extension_9614eff520454054b6d79fbe0c7a5491_termsOfUseConsentDateTime;
additionalData[haspassword] = userToUpdate.extensionAttributes.extension_9614eff520454054b6d79fbe0c7a5491_haspassword;
additionalData[dateOfBirth] = userToUpdate.extensionAttributes.extension_9614eff520454054b6d79fbe0c7a5491_dateOfBirth;
var tempUser = new User
{
AdditionalData = additionalData
};
await _graphApiService.EditUserAsync(userId, tempUser);
这篇关于使用Graph API SDK更新Azure B2C自定义属性错误:目标实体集当前不支持该请求AdditionalData: 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用Graph API SDK更新Azure B2C自定义属性错误:目标实体集当前不支持该请求AdditionalData:
基础教程推荐
- WPF 模态进度窗口 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
