我们已经使用Microsoft Graph API一段时间来设置扩展属性的值。以前我们使用过Microsoft.Azure.ActiveDirectory.GraphClient,但是一年之后就有了一个Microsoft.Graph Nuget包。使用Microsoft.Azure.ActiveDirectory.GraphClient有一个名为SetExtendedProperty的方法,但Microsoft.Graph包中没有这样的东西。有没有人建议如何使用Microsoft.Graph包设置扩展属性?
如果您需要更多信息,请告诉我们!
答案 0 :(得分:2)
您可以使用microsoft graph sdk v1.4.0版本创建架构扩展。相关讨论和代码示例here和here仅供参考。
例如,要为组创建架构扩展:
var types = [{id:1, type:'Type 2'}, {id:2, type:'Type 5'}, {id:3, type:'Type 1'}, {id:4, type:'Type 2'}];
var res = types.reduce(function(arr, obj) {
if(obj.type === 'Type 2') {
arr.push({
id: obj.id
})
}
return arr
}, [])
console.log(res)
然后为扩展名创建一个类:
// Create a schema extension for groups.
SchemaExtension extensionDefinition = new SchemaExtension()
{
Description = "This extension correlates a group with a foreign database.",
Id = $"crmForeignKey", // Microsoft Graph will prepend 8 chars
Properties = new List<ExtensionSchemaProperty>()
{
new ExtensionSchemaProperty() { Name = "fid", Type = "Integer" }
},
TargetTypes = new List<string>()
{
"Group"
}
};
// Create the schema extension. This results in a call to Microsoft Graph.
SchemaExtension schemaExtension = await graphClient.SchemaExtensions.Request().AddAsync(extensionDefinition);
接下来,通过组的更新[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class MyDBExtensionClass
{
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "fid", Required = Newtonsoft.Json.Required.Default)]
public int FID { get; set; }
public MyDBExtensionClass(int fid)
{
FID = fid;
}
}
属性将架构扩展属性设置为现有组:
AdditionalData
您还可以将扩展名添加到新的创建组,如上面链接所示。
更新:
您的要求是将架构扩展属性设置为user,然后更新user {/ p>}的 // Update a group.
// This snippet changes the group name.
// This snippet requires an admin work account.
public async Task<List<ResultsItem>> UpdateGroup(GraphServiceClient graphClient, string id, string name)
{
List<ResultsItem> items = new List<ResultsItem>();
IDictionary<string, object> extensionInstance = new Dictionary<string, object>();
extensionInstance.Add(extensionIDYouGet, new MyDBExtensionClass(1213));
// Update the group.
await graphClient.Groups[id].Request().UpdateAsync(new Group
{
DisplayName = Resource.Updated + name,
AdditionalData= extensionInstance
});
items.Add(new ResultsItem
{
// This operation doesn't return anything.
Properties = new Dictionary<string, object>
{
{ Resource.No_Return_Data, "" }
}
});
return items;
}
属性
AdditionalData
如果要为用户实体创建架构扩展, await graphClient.Users["ID"].Request().UpdateAsync(new User
{
DisplayName = Resource.Updated + name,
AdditionalData = extensionInstance
});
值应包含在SchemaExtension对象的User
属性中。