使用Office 365 OAuth API对SharePoint端点进行身份验证
我正在尝试使用提到的Office 365 API访问sharepoint在线网站 我正在获取身份验证令牌并调用发现服务,如下所示:使用Office 365 OAuth API对SharePoint端点进行身份验证,sharepoint,office365,Sharepoint,Office365,我正在尝试使用提到的Office 365 API访问sharepoint在线网站 我正在获取身份验证令牌并调用发现服务,如下所示: httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken); httpClient.DefaultRequestHeaders.Add("A
httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
httpClient.DefaultRequestHeaders.Add("Accept", "application/json; odata=verbose");
response = await httpClient.GetAsync(new Uri("https: / /api.office.com/discovery/me/services"));
data = await response.Content.ReadAsStringAsync();
我在结果中获得以下类型的端点URL:
https://sometenant-my.sharepoint.com/personal/sometenant\u data\u onmicrosoft\u com//api
https://outlook.office365.com/api/v1.0
httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
httpClient.DefaultRequestHeaders.Add("Accept", "application/json; odata=verbose");
response = await httpClient.GetAsync("https://sometenant.sharepoint.com/_api/web/lists/getByTitle('Documents')/items");
data = await response.Content.ReadAsStringAsync();
我在响应流中得到以下信息:
"{\"error\":\"invalid_client\",\"error_description\":\"Invalid audience Uri 'Microsoft.SharePoint'.\"}"
响应中的错误是:
{StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
x-ms-diagnostics: 3000003;reason="Invalid audience Uri 'Microsoft.SharePoint'.";category="invalid_client"
SPRequestGuid: 8462cf9c-c093-1000-a3da-fc5e1aab16c1
request-id: 8462cf9c-c093-1000-a3da-fc5e1aab16c1
SPRequestDuration: 37
SPIisLatency: 25
MicrosoftSharePointTeamServices: 16.0.0.3431
X-Content-Type-Options: nosniff
X-MS-InvokeApp: 1; RequireReadOnly
Date: Mon, 24 Nov 2014 22:45:46 GMT
P3P: CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI"
Server: Microsoft-IIS/7.5
WWW-Authenticate: Bearer realm="xxxxxx-xxxx-xxxxx-xxxx-xxxxxxxx",client_id="xxxxxxxx-xxx-xxxx-xxxx-000000000000",trusted_issuers="xxxxxxx-xxxx-xxx-xxx-000000000000@*,https : // sts.windows.net/*/,00000003-0000-xxxxx-ce00-000000000000@xxxxxxxx-xxxxx-11e1-xxxx-xxxxxxx",authorization_uri="https://login.windows.net/common/oauth2/authorize"
X-Powered-By: ASP.NET
Content-Length: 93
}}
我相信我应该能够使用Office 365 API访问SharePoint数据
我已授予应用程序对所有网站集权限的完全控制权
请告知我是否遗漏了任何内容。最初尝试获取访问令牌时,您的目标URL与SharePoint所需的不同。我不知道为什么,Office365 access\u令牌在SharePoint上运行似乎是合乎逻辑的,但事实并非如此 因此,我假设您在SharePoint注册的应用程序中有客户id和客户机密。如果没有,则有两种方法可以注册新应用程序:
这将返回一个带有访问令牌和刷新令牌的响应,现在使用此令牌,您将能够访问SharePoint REST API。您是如何使用此令牌的?找到了任何好的示例,或者您使其工作了吗?