gpt4 book ai didi

图形客户端中的 Azure 架构扩展

转载 作者:行者123 更新时间:2023-12-01 13:47:25 25 4
gpt4 key购买 nike

无论我尝试什么,我都无法在 User 对象上设置扩展属性,这是一段可重现的代码:

public async Task CleanTest(string extName)
{
ExtensionProperty ep = new ExtensionProperty
{
Name = extName,
DataType = "String",
TargetObjects = { "User" }
};

App app = (App)(await _client.Applications.Where(a => a.AppId == _managementAppClientId).ExecuteSingleAsync());
app.ExtensionProperties.Add(ep);
await app.UpdateAsync();

GraphUser user = (GraphUser)(await _client.Users.Where(u => u.UserPrincipalName.Equals("email")).ExecuteSingleAsync());
string propName = FormatExtensionPropertyName(extName); //formats properly as extesion_xxx_name
user.SetExtendedProperty(propName, "testvalue");
//user.SetExtendedProperty(extName, "testvalue");
await user.UpdateAsync(); // fails here
}

根据 Fiddler 的 user.UpdateAsync() 甚至不会消失,并且应用程序失败并出现异常:

“类型“Microsoft.Azure.ActiveDirectory.GraphClient.Internal.User”上不存在属性“extension_e206e28ff36244b19bc56c01160b9cf0_UserEEEqdbtgd3ixx2”。请确保仅使用该类型定义的属性名称。”

最佳答案

此问题也在此处进行跟踪: https://github.com/Azure-Samples/active-directory-dotnet-graphapi-console/issues/28

对于那些想要使用 5.7 版 OData 库而不是重定向到 v5.6.4 版本的用户,我有针对此错误的替代解决方法。

添加请求管道配置处理程序。

// initialize in the usual way
ActiveDirectoryClient activeDirectoryClient =
AuthenticationHelper.GetActiveDirectoryClientAsApplication();
// after initialization add a handler to the request pipline configuration.
activeDirectoryClient.Context
.Configurations.RequestPipeline
.OnMessageWriterSettingsCreated(UndeclaredPropertyHandler);

在处理程序中,将编写器设置上的 ODataUndeclaredPropertyBehaviorKinds 值更改为 SupportUndeclaredValueProperty。

private static void UndeclaredPropertyHandler(MessageWriterSettingsArgs args)
{
var field = args.Settings.GetType().GetField("settings",
BindingFlags.NonPublic | BindingFlags.Instance);
var settingsObject = field?.GetValue(args.Settings);
var settings = settingsObject as ODataMessageWriterSettings;
if (settings != null)
{
settings.UndeclaredPropertyBehaviorKinds =
ODataUndeclaredPropertyBehaviorKinds.SupportUndeclaredValueProperty;
}
}

关于图形客户端中的 Azure 架构扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34900004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com