I'm planning to make a job, coded in Java, on a Linux server that is scheduled to once a day upload a file to a SharePoint on-premises 2013, using the REST API. How can I authenticate this client job? I have googled, but am still struggling to get a clear overview over my options.
Asked
Active
Viewed 1,349 times
5
-
I did similar once where back-end code was written in C# and sharepoint authentication was provided by sharepoint app that i registered on a site with Full control permissions and app only policy. Try investigating this SP App option. – Alex K Mar 15 '17 at 14:48
1 Answers
1
Theirs two ways to do this. One through using the SharePoint App/Add-In Model, the other using Network Authentication with a Windows Credential. Given the question, I'm guessing the latter will be simpler and a better match to setup.
This will create a windows authentication credential that you can use for your http requests.
RequestConfig reqConfig = RequestConfig.custom().setTargetPreferredAuthScemes(Arrays.asList(AuthSchemes.NTLM)).setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC)).build();
CredentialsProvider credProvider = new BasicCredentialsProvider();
credProvider.setCredentials(AuthSocpe.ANY, new NTCredentials("user", "pass", "currentHost", "domainName"));
HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credProvider).setDefaultRequestConfig(reqConfig).build();
// construct your http request
HttpResponse response = client.execute(HttpHost, HttpPost);

Maarten
- 451
- 2
- 5
-
Just a note, this is how to authenticate to SharePoint in Java and is not platform dependent on what is hosting the java application. SharePoint's login by default uses Windows Authentication, so you tell Java to use Windows Auth and give it a username and password. :) – Maarten Mar 21 '17 at 22:51