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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With