使用Graph API SDK更新Azure B2C自定义属性错误:目标实体集当前不支持该请求AdditionalData:

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:)
本文介绍了使用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: 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)