Microsoft Graph client error : Authentication challenge is required
Microsoft Graph client error : Authentication challenge is required
我正在尝试使用 Microsoft 在 NuGet 中提供的 Graph SDK 访问 Office 365 用户,我的代码是:
var cca = ConfidentialClientApplicationBuilder
.Create("ClientId")
.WithClientSecret("ClientSecret")
.WithTenantId("TenantId")
.Build();
List<string> scopess = new List<string>();
scopes.Add("https://graph.microsoft.com/.default");
scopes.Add("Calendars.Read");
// i tried each scope alone and same result
var authenticationProvider = new AuthorizationCodeProvider(cca, scopes.ToArray());
GraphServiceClient graphClient = new GraphServiceClient(authenticationProvider);
var x = await graphClient.Users.Request().GetAsync();
最后一行出现错误
Authentication challenge is required
我的 Azure Active Directory 应用程序注册设置是:
可能我做错了什么但不确定是什么!
我正在使用 Microsoft Docs 作为参考
您正在使用 client credential provider。
将var authenticationProvider = new AuthorizationCodeProvider(cca, scopes.ToArray());
替换为ClientCredentialProvider authenticationProvider = new ClientCredentialProvider(cca);
请注意,您定义了 GraphServiceClient graphClient
,但您在下一行中使用了 graphClient2
:graphClient2.Users.Request().GetAsync()
。请查收。
我正在尝试使用 Microsoft 在 NuGet 中提供的 Graph SDK 访问 Office 365 用户,我的代码是:
var cca = ConfidentialClientApplicationBuilder
.Create("ClientId")
.WithClientSecret("ClientSecret")
.WithTenantId("TenantId")
.Build();
List<string> scopess = new List<string>();
scopes.Add("https://graph.microsoft.com/.default");
scopes.Add("Calendars.Read");
// i tried each scope alone and same result
var authenticationProvider = new AuthorizationCodeProvider(cca, scopes.ToArray());
GraphServiceClient graphClient = new GraphServiceClient(authenticationProvider);
var x = await graphClient.Users.Request().GetAsync();
最后一行出现错误
Authentication challenge is required
我的 Azure Active Directory 应用程序注册设置是:
可能我做错了什么但不确定是什么! 我正在使用 Microsoft Docs 作为参考
您正在使用 client credential provider。
将var authenticationProvider = new AuthorizationCodeProvider(cca, scopes.ToArray());
替换为ClientCredentialProvider authenticationProvider = new ClientCredentialProvider(cca);
请注意,您定义了 GraphServiceClient graphClient
,但您在下一行中使用了 graphClient2
:graphClient2.Users.Request().GetAsync()
。请查收。