如何使用 Microsoft Graph Beta 更新信任框架策略?
How to update Trust Framework Policy using Microsoft Graph Beta?
由此Microsoft doc we see it's possible to update a Trust Framework Policy. Anyways I couldn't find a way of doing the same using Microsoft Graph Client Beta SDK.
现在我有了这段代码,其中 policyId = B2C_1A_TrustFrameworkExtensions
:
var policy = await graphServiceClient
.TrustFramework.Policies[policyId]
.Request()
.GetAsync();
那我想更新这个政策的内容,打电话:
await graphServiceClient
.TrustFramework.Policies[policyId]
.Request()
.UpdateAsync(policy);
但是我在从 Microsoft Graph 返回的策略对象中看不到任何 属性,我可以在其中传递修改后的策略 XML 内容。
我的问题是:可以使用 Microsoft Graph Beta 客户端完成吗?
Microsoft Graph 中的 TrustFramework policies
在 api 中作为 blob 可用。请注意 get
和 put
api 中的 $value 参数。所以通常的访问数据的方式是行不通的。下面给出了如何读写策略的示例代码
var requestBuilder = graphServiceClient.TrustFramework.Policies[policyId];
var url = requestBuilder.AppendSegmentToRequestUrl("$value");
var builder = new TrustFrameworkPolicyContentRequestBuilder(url, graphServiceClient);
// Read a policy
using (var stream = await builder.Request().GetAsync())
using (StreamReader sr = new StreamReader(stream))
{
var policyContent = sr.ReadToEnd();
Console.WriteLine("Policy Read " + policyContent);
}
string path = @"<FilePath>";
// Write a policy. lets say path has the to be uploaded file content
using (StreamReader sr = new StreamReader(path))
using (var stream = await builder.Request().PutAsync(sr.BaseStream))
using (StreamReader osr = new StreamReader(stream))
{
Console.WriteLine("Updated policy content" + osr.ReadToEnd());
}
由此Microsoft doc we see it's possible to update a Trust Framework Policy. Anyways I couldn't find a way of doing the same using Microsoft Graph Client Beta SDK.
现在我有了这段代码,其中 policyId = B2C_1A_TrustFrameworkExtensions
:
var policy = await graphServiceClient
.TrustFramework.Policies[policyId]
.Request()
.GetAsync();
那我想更新这个政策的内容,打电话:
await graphServiceClient
.TrustFramework.Policies[policyId]
.Request()
.UpdateAsync(policy);
但是我在从 Microsoft Graph 返回的策略对象中看不到任何 属性,我可以在其中传递修改后的策略 XML 内容。
我的问题是:可以使用 Microsoft Graph Beta 客户端完成吗?
Microsoft Graph 中的 TrustFramework policies
在 api 中作为 blob 可用。请注意 get
和 put
api 中的 $value 参数。所以通常的访问数据的方式是行不通的。下面给出了如何读写策略的示例代码
var requestBuilder = graphServiceClient.TrustFramework.Policies[policyId];
var url = requestBuilder.AppendSegmentToRequestUrl("$value");
var builder = new TrustFrameworkPolicyContentRequestBuilder(url, graphServiceClient);
// Read a policy
using (var stream = await builder.Request().GetAsync())
using (StreamReader sr = new StreamReader(stream))
{
var policyContent = sr.ReadToEnd();
Console.WriteLine("Policy Read " + policyContent);
}
string path = @"<FilePath>";
// Write a policy. lets say path has the to be uploaded file content
using (StreamReader sr = new StreamReader(path))
using (var stream = await builder.Request().PutAsync(sr.BaseStream))
using (StreamReader osr = new StreamReader(stream))
{
Console.WriteLine("Updated policy content" + osr.ReadToEnd());
}