如何使用Microsoft Graph Beta更新信任框架策略?

问题描述 投票:1回答:1

从此Microsoft doc我们看到可以更新信任框架策略。无论如何,我找不到使用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内容。

enter image description here

我的问题是:可以使用Microsoft Graph Beta客户端来完成吗?

microsoft-graph azure-ad-b2c beta identity-experience-framework trust-framework-policy
1个回答
0
投票

Microsoft Graph中的TrustFramework policies在api中可以作为blob使用。请注意getput 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());
        }
© www.soinside.com 2019 - 2024. All rights reserved.