0

我们正在使用 Sharepoint Rest API 来索引内容。

由于客户的安全要求,我们只能将在 Sharepoint 管理中心授予的 API 权限与带有密钥的仅限应用程序主体结合使用。

我们在 Azure AD 管理中心注册了一个应用程序并授予它权限,如此所述。

然后,我们编写了一段 Java 代码来调整此处描述的请求以检索 JWT:

List<NameValuePair> params = new ArrayList<>(10);
        params.add(new BasicNameValuePair("grant_type", "client_credentials"));
        params.add(new BasicNameValuePair("client_id", clientId + "@" + directoryId));
        params.add(new BasicNameValuePair("client_secret", clientSecret));
        params.add(new BasicNameValuePair("resource", "00000003-0000-0ff1-ce00-000000000000/" + targetHost + "@" + directoryId));

        try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
            HttpPost post = new HttpPost("https://accounts.accesscontrol.windows.net/" + directoryId + "/tokens/OAuth/2");
            post.setEntity(new UrlEncodedFormEntity(params, Consts.UTF_8));
            String result;
            try (CloseableHttpResponse response = httpClient.execute(post)) {
                if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK)
                    throw new SharepointClient.HttpStatusException(response.getStatusLine().getStatusCode());
                result = Strings.fromUtf8(IO.readAll(response.getEntity().getContent()));
            }
            accessToken = new JsonData(result).get("access_token");
        }

然后,我们将令牌用作对 API 的所有请求的授权标头中的不记名令牌。

这在大约一周前工作了几个月。从那时起,我们只收到 403 条回复。

HttpResponseProxy{HTTP/1.1 403 Forbidden [Cache-Control: private, max-age=0, Transfer-Encoding: chunked, Content-Type: application/json;odata=verbose;charset=utf-8, Expires: Wed, 30 Sep 2020 09:58:49 GMT, Last-Modified: Thu, 15 Oct 2020 09:58:49 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", X-SharePointHealthScore: 2, X-MSDAVEXT_Error: 917656; Zugriff+verweigert.+Zum+%c3%96ffnen+von+Dateien+an+diesem+Speicherort+m%c3%bcssen+Sie+zun%c3%a4chst+zur+Website+wechseln+und+die+Option+zur+automatischen+Anmeldung+aktivieren., DATASERVICEVERSION: 3.0, X-AspNet-Version: 4.0.30319, SPRequestGuid: f7dd839f-10d1-2000-73fa-40c47dd29bbb, request-id: f7dd839f-10d1-2000-73fa-40c47dd29bbb, MS-CV: n4Pd99EQACBz+kDEfdKbuw.0, Strict-Transport-Security: max-age=31536000, X-FRAME-OPTIONS: SAMEORIGIN, Content-Security-Policy: frame-ancestors 'self' teams.microsoft.com *.teams.microsoft.com *.skype.com *.teams.microsoft.us local.teams.office.com *.powerapps.com *.yammer.com *.officeapps.live.com *.stream.azure-test.net *.microsoftstream.com;, X-Powered-By: ASP.NET, MicrosoftSharePointTeamServices: 16.0.0.20530, X-Content-Type-Options: nosniff, X-MS-InvokeApp: 1; RequireReadOnly, X-MSEdge-Ref: Ref A: 330CB0BA15E647CC8B732FCC45D4F950 Ref B: AM3EDGE0620 Ref C: 2020-10-15T09:58:49Z, Date: Thu, 15 Oct 2020 09:58:49 GMT] ResponseEntityProxy{[Content-Type: application/json;odata=verbose;charset=utf-8,Chunked: true]}}

错误消息是德语(我不知道为什么,整个系统设置为英语)。它说:“访问被拒绝。要在此位置打开文件,您必须先访问网站并激活自动登录选项。”

有谁知道可能发生了什么变化?我们需要更改请求中的某些内容吗?

我们已经检查过:

  • 秘密未过期
  • 通过证书和 Azure AD 管理中心权限的身份验证仍然有效(相同的 API 请求,只是使用 msal4j 完成了令牌检索)
  • 通过 Postman 发送令牌请求和 API 请求会导致相同的结果
4

1 回答 1

0

错误的原因不是您缺少权限。根据错误信息Access denied. To open files in this location, you have to first go to the website and activate the option for automatic login

你需要:

1. 向 Office 365 进行身份验证。

2.将您的 SharePoint Online 网站添加到受信任的网站。

3.检查WebClient服务的状态。

请参阅:对连接到 SharePoint Online 的映射网络驱动器进行故障排除

于 2020-10-30T09:44:54.000 回答