gpt4 book ai didi

c# - 如何在 C# 中检索 azure 安全组

转载 作者:行者123 更新时间:2023-12-03 02:12:12 24 4
gpt4 key购买 nike

我正在尝试从 azure 安全组检索用户列表,但是我遇到了问题,因为我不知道在 C# 中执行此操作的最佳且简单的方法。任何帮助/指导和示例代码将不胜感激。

最佳答案

要从 Azure 安全组检索用户列表,请确保授予以下 API 权限:

enter image description here

请尝试在此 SO Thread 中使用 Jason Pan 编写的以下脚本如下所示:

 public async Task<JsonResult> sample()
{
var clientId = Your_Client_ID;
var clientSecret = Your_Client_Secret;
var scopes = new[] { "https://graph.microsoft.com/.default" };
var tenantId = Your_Tenant_ID;
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
var clientSecretCredential = new ClientSecretCredential(
tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
try
{
var members = await graphClient.Groups["Your_Group_ID"].Members.Request().GetAsync();
return Json(members);
}
catch (Exception e)
{
return Json("");
throw;
}
}

关于c# - 如何在 C# 中检索 azure 安全组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73034908/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com