Authentication from NativeScript App(android/ios) to Sharepoint 2013 REST API


April 2019


651 time


I'm trying to call Sharepoint 2013 REST API from an application developped with NativeScript(android/ios).

Using xhr or fetch NativeScript module I'm not able to authenticate correctly and call rest api.

Using Java I'm able to connect to the sharepoint server and call Rest API without problem Using this maven dependency: org.apache.httpcomponents httpclient 4.4.1.

public class SharePointClientAuthentication {

public static void main(String[] args) throws Exception {
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
            new AuthScope(AuthScope.ANY),
            new NTCredentials("username", "password", "https://hostname", "domain"));
    CloseableHttpClient httpclient = HttpClients.custom()
    try {
        HttpGet httpget = new HttpGet("http://hostname/_api/web/lists");

        System.out.println("Executing request " + httpget.getRequestLine());
        CloseableHttpResponse response = httpclient.execute(httpget);
        try {
        } finally {
    } finally {

Any one know what's the equivalent to the java code with NativeScript or a way to get Windows authentication(NTLM) to work.

Thanks in advance.

1 answers


Initially I thought this should be handled by the native HTTP library and exposed as a part of the XMLHttpRequest implementation in NativeScript, but then I discovered ntlm.js. It's a small library that takes care of the NTLM challenge-response for you.

I patched it up a bit, to get rid of the browser dependency and push some polyfills, and got it running. I put up a demo project here: