Authentication to online Sharepoint
-
01-01-2021 - |
Question
I am authenticating with cookie to online Sharepoint, as answered here:
REST - Authentication to online Sharepoint
When I try to authenticate I get 401 error.
This is my code:
List<String> fileList = new ArrayList<>();
try {
//here I get cookie value
CookieStore cookieStore = getCookieStore(.....);
HttpClient httpClient = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
String uri = URL + "/" + "_api/web/GetFolderByServerRelativeUrl(\'" + FOLDER_NAME + "\')/files";
HttpGet httpGet = new HttpGet(uri);
httpGet.addHeader("Accept", "application/json;odata=verbose");
httpGet.addHeader("X-FORMS_BASED_AUTH_ACCEPTED", "f");
// Make the request.
HttpResponse response = httpClient.execute(httpGet);
// Process the result
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == 200) {
......
}
} catch (Exception e) {
log.error("", e);
}
My cookie store is something like this: [[version: 0][name: SPOIDCRL][value: 77u/PD94bWwgdmVyc2lvbj.......
But, I am geting 401 with error: HTTP/1.1 401 Unauthorized
Again I can't authorise to SP. Can you help me one more time?
Thanks
La solution
I have not tried the Java client. But I can successfully issue the same request with the HttpClient class in the .NET framework. Make sure the cookie has the format:
SPOIDCRL=77u/PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48...
Also, you do not need to include the X-FORMS_BASED_AUTH_ACCEPTED header.
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange