【发布时间】:2018-01-04 17:11:12
【问题描述】:
我需要从 C# 的服务器端通过 Sharepoint REST api 执行此查询 https://<tenant>.sharepoint.com/_api/search/query?querytext=%27contenttype:articles%27。
我有来自 MVC 门户的 Oauth2 连接,所以我的目标是从连接中检索令牌并将其作为不记名令牌发送到共享点端点。
我的意思是这样的
string userObjectID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
AuthenticationContext authContext = new AuthenticationContext(Startup.Authority, new NaiveSessionCache(userObjectID));
ClientCredential credential = new ClientCredential(clientId, appKey);
AuthenticationResult result = await authContext.AcquireTokenSilentAsync("https://<tenant>.sharepoint.com/", credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));
HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "https://<tenant>.sharepoint.com/_api/search/query?querytext=%27contenttype:articles%27");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
HttpResponseMessage response = await client.SendAsync(request);
但显然,我无法检索令牌...
另一方面,我使用 ADv2 和 GraphServiceClient 构建了一个运行良好的应用,但我不知道如何在图形模型中翻译查询(而且我没有任何管理员同意)。
所以,我有 2 种方法可以解决我的问题,我希望更好地使用带有 microsoft graph api 的第二个选项,但欢迎提供任何帮助。
谢谢。
【问题讨论】:
标签: c# rest sharepoint azure-active-directory microsoft-graph-api