使用GraphServiceClient检索Azure广告成员的组信息

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

我想在我的后端应用程序中检索Azure广告组的所有成员。我遵循了herehere步骤,这是我的代码:enter image description here

但是使用此方法时,我总是会收到此错误:Microsoft.Graph.ServiceException:代码:generalException消息:An发送请求时发生错误。

---> Microsoft.Graph.Auth.AuthenticationException:代码:authenticationChallengeRequired消息:身份验证挑战为必填。

有人可以帮我吗?我没有发现此特定错误。

asp.net authentication graph azure-active-directory microsoft-graph
1个回答
0
投票

显然,这些参数(clientId / tenantId / clientSecret / groupId)需要替换为特定的字符串。

您可以通过应用程序注册->概述:

找到clientIdtenantId

enter image description here

[clientSecret通过应用程序注册->证书和机密:

enter image description here

groupId通过Azure Active Directory->组:

enter image description here


您还可以将特定的字符串存储在配置文件中,并读取文件中的字符串。并且sample将帮助您理解它。

AccountController.cs:

IConfidentialClientApplication daemonClient;
                daemonClient = ConfidentialClientApplicationBuilder.Create(Startup.clientId)
                    .WithAuthority(string.Format(AuthorityFormat, tenantId))
                    .WithRedirectUri(Startup.redirectUri)
                    .WithClientSecret(Startup.clientSecret)
                    .Build();

Web.config:

  <add key="ida:ClientId" value="[Enter your client ID]" />
  <add key="ida:ClientSecret" value="[Enter your client secret]" />

Startup.Auth.cs:

public static string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
public static string clientSecret = ConfigurationManager.AppSettings["ida:ClientSecret"];
public static string redirectUri = "https://localhost:44316/";
© www.soinside.com 2019 - 2024. All rights reserved.