Update Azure B2C custom attributes using Graph API SDK Error: "The request is currently not supported on the targeted entity set AdditionalData:\r\n
Update Azure B2C custom attributes using Graph API SDK Error: "The request is currently not supported on the targeted entity set AdditionalData:\r\n
到目前为止,似乎还没有实现它的标准方法。
经过一段时间的研究,我得出了以下代码,不幸的是 returns 我遇到了一个模糊的错误:
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\r\nMessage: The request is currently not supported on the targeted entity set\r\nInner error:\r\n\tAdditionalData:\r\n\tdate: 2022-01-14T21:23:33\r\n\trequest-id: d6c9c8b9-47fc-4aa0-bb9b-328a5b260753\r\n\tclient-request-id: d6c9c8b9-47fc-4aa0-bb9b-328a5b260753\r\nClientRequestId: d6c9c8b9-47fc-4aa0-bb9b-328a5b260753\r\n"
--
附加信息:
My Graph API 应用具有以下委派权限:
Directory.AccessAsUser.All
Directory.ReadWrite.All
User.Read
User.ReadWrite.All
Graph 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);
到目前为止,似乎还没有实现它的标准方法。
经过一段时间的研究,我得出了以下代码,不幸的是 returns 我遇到了一个模糊的错误:
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\r\nMessage: The request is currently not supported on the targeted entity set\r\nInner error:\r\n\tAdditionalData:\r\n\tdate: 2022-01-14T21:23:33\r\n\trequest-id: d6c9c8b9-47fc-4aa0-bb9b-328a5b260753\r\n\tclient-request-id: d6c9c8b9-47fc-4aa0-bb9b-328a5b260753\r\nClientRequestId: d6c9c8b9-47fc-4aa0-bb9b-328a5b260753\r\n"
--
附加信息:
My Graph API 应用具有以下委派权限:
Directory.AccessAsUser.All
Directory.ReadWrite.All
User.Read
User.ReadWrite.All
Graph 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);