Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SharePoint on-premises 2013 REST authentication

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.

like image 998
matthiash Avatar asked Nov 09 '22 00:11

matthiash


1 Answers

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);
like image 162
Maarten Avatar answered Nov 15 '22 04:11

Maarten