Closed cpesch closed 3 years ago
Have you tried with the OnPremises implementation? In the code example you provided you are instantiating a Online implementation (that should work with an online office365 sharepoint instance). If you are using a company OnPremises . Test with this and let me know if it works for you.
Actually, I assumed that *.sharepoint.com are Online implementations. Anyway, I've tried the OnPremises client and always receive a 401.
Could it be that I've interpreted domain, spSiteUrl and spSitePrefix incorrectly? They seem to have a different meaning than for the Online client
I assume domain is the AD-domain, i.e. everything before the two backslashes. in uppercase characters? And spSiteUrl is the FQDN?
public class SharepointDownloaderOnPremise {
public static void main(String[] args) throws Exception {
String user = "username";
String passwd = "password";
String domain = "AD-DOMAIN";
String spSiteUrl = "company.sharepoint.com";
String spSitePrefix = "/sites/asite";
PLGSharepointClient wrapper = new PLGSharepointOnPremisesClient(user, passwd, domain, spSiteUrl, spSitePrefix);
JSONObject result = wrapper.getAllLists("{}");
System.out.println(result);
}
}
The online implementation tries to login with the microsoft SSO obtaining a token valid for online instances. Using an OnPremises sharepoint the auth is done by creating NTCredentials to add as a header
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, new NTCredentials(user, passwd, spSiteUrl, domain));
CloseableHttpClient httpClient = HttpClients.custom()
.setDefaultCredentialsProvider(credsProvider)
.build();
So in this case the meaning are related to this constructor org.apache.http.auth.NTCredentials.NTCredentials(String userName, String password, String workstation, String domain)
So userName.- an AD user name (without domain) passwd.- the user password to login against your AD spSiteUrl.- the workstation name of the sharepoint on premises instance domain.- the user domain, in AD the domain containing the user used to login.
Let me know if this helps, if not i can provide a more flexible implementation where you can provide a token generated with other tools to access your sp instance.
P.D.- sorry for the time in answering but i have busy days at work.
@kikovalle the error was related to a missing app registration and authorization
@kikovalle the error was related to a missing app registration and authorization
Thanks for the info as i was trying to get some time to try to reproduce the issue and fix it, but unfortunately i am a bit busy at work.
Hi,
I've got the typical simple cmd line client for accessing the company Sharepoint which is secured by the company AD:
and I always get the above error codes
`<?xml version="1.0" encoding="utf-8"?> <S:Envelope xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wst="http://schemas.xmlsoap.org/ws/2005/02/trust" xmlns:S="http://www.w3.org/2003/05/soap-envelope">