【问题标题】:How to update Trust Framework Policy using Microsoft Graph Beta?如何使用 Microsoft Graph Beta 更新信任框架策略?
【发布时间】:2020-03-25 05:44:05
【问题描述】:

从这个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 内容。

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

【问题讨论】:

    标签: microsoft-graph-api azure-ad-b2c beta identity-experience-framework


    【解决方案1】:

    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());
            }
    

    【讨论】:

    • 嘿阿布舍克...谢谢你的回答!我没有使用此代码,因为我直接调用端点而不是使用客户端 SDK。这肯定会在未来有所帮助。
    猜你喜欢
    • 1970-01-01
    • 2023-02-17
    • 1970-01-01
    • 1970-01-01
    • 2022-10-25
    • 1970-01-01
    • 2020-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多