c# - C# / Azure AD / Graph API - 使用 Open Extensions 设置其他用户属性
问题描述
我正在尝试使用 Microsoft Graph 向我在 Azure Active Directory 中新创建的用户对象添加一些自定义属性。
我的代码如下所示:
public async Task addUser(string firstName, string lastName)
{
var mail = firstName.ToLower() + "." + lastName.ToLower() + "@mail.com";
var user = new User
{
AccountEnabled = true,
UserPrincipalName = mail,
PasswordProfile = new PasswordProfile
{
ForceChangePasswordNextSignIn = true,
Password = randomString(10) // I wrote a dedicated function here
},
};
var res = await graphServiceClient
.Users
.Request()
.AddAsync(user);
await addExtension(res.Id);
}
public async Task addExtension(string id)
{
var extension = new OpenTypeExtension
{
ExtensionName = "com.test.test", // necessary I guess
AdditionalData = new Dictionary<string, object>
{
{"NewAttribute1", "Batman"},
{"NewAttribute2" , "Spiderman"}
}
};
await graphServiceClient
.Users[id]
.Extensions
.Request()
.AddAsync(extension);
}
我目前收到的错误消息是:
Message: One or more properties contains invalid values.
Inner error:
AdditionalData:
...
我在这里定位了自己:
希望有人能帮忙,谢谢!
解决方案
我设法使我的程序工作。上面的代码实际上是正确的,经过一些调整,现在对我来说很好。
我必须单独阅读扩展名,如下所示。访问该user.Extensions
属性对我不起作用。希望这对将来的某人有所帮助:)
public async Task getUserExtensions(string userID, string extensionID)
{
var extension = await configuration
.configure()
.Users[userID]
.Extensions[extensionID]
.Request()
.GetAsync();
foreach (var item in extension.AdditionalData)
{
Console.WriteLine($"{item.Key} | {item.Value}");
}
}
推荐阅读
- ios - 实例成员不能用于“AppDelegate”类型
- list - 如何从 Robot 框架中的整数项列表中找到最大的数字?
- reactjs - 如何在 Next.js 中获取来源或域名
- sass - phpstorm 编译 sass 缩小
- swift - 为什么 for 循环中并发队列上的 .async 与 DispatchQueue.concurrentPerform 的行为不同?
- python - 来自 csv 文件的列中的中间数据
- moodle - Moodle Formulas中的JSXGraph有两个板:绑定到输入字段不起作用
- swift - 无法快速将文件写入桌面
- reactjs - 对 react + redux 的开玩笑测试在道具中说未定义的值
- python - JiTCDDE 集成问题