1

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();
    credsProvider.setCredentials(
            new AuthScope(AuthScope.ANY),
            new NTCredentials("username", "password", "https://hostname", "domain"));
    CloseableHttpClient httpclient = HttpClients.custom()
            .setDefaultCredentialsProvider(credsProvider)
            .build();
    try {
        HttpGet httpget = new HttpGet("http://hostname/_api/web/lists");

        System.out.println("Executing request " + httpget.getRequestLine());
        CloseableHttpResponse response = httpclient.execute(httpget);
        try {
            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            EntityUtils.consume(response.getEntity());
        } finally {
            response.close();
        }
    } finally {
        httpclient.close();
    }
}
}

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.

2
  • You can take a look at this plugin npmjs.com/package/nativescript-okhttp. For better visibility, you can open an issue in {N} GitHub repository about implementing this feature in the http module. Commented Jan 7, 2016 at 8:48
  • Thanks, I'll try the example of Hristo Deshev. Commented Jan 8, 2016 at 10:21

1 Answer 1

1

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:

https://github.com/hdeshev/nativescript-ntlm-demo

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for this demo, I will give it a try against the rest sharepoint api! I'm thinking to write a nativescript package to handle Sharepoint Rest operation whith three authentication types ntlm, basic, online.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.