从 NativeScript 应用程序 (android/ios) 到 Sharepoint 2013 REST API 的身份验证

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

我正在尝试从使用 NativeScript(android/ios) 开发的应用程序调用 Sharepoint 2013 REST API。

使用 xhr 或获取 NativeScript 模块我无法正确验证并调用 rest api。

使用 Java 我能够连接到 Sharepoint 服务器并调用 Rest API 没有问题 使用此 Maven 依赖项: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();
    }
}
}

任何人都知道什么是与 NativeScript 的 java 代码或使 Windows 身份验证 (NTLM) 起作用的方法。

提前致谢。

最初我认为这应该由本机 HTTP 库处理并作为 NativeScript 中 XMLHttpRequest 实现的一部分公开,但后来我发现 ntlm.js。这是一个为您处理 NTLM challenge-response 的小型图书馆。

我对它进行了一些修补,摆脱了对浏览器的依赖并推送了一些 polyfill,并得到了它 运行。我在这里放了一个演示项目:

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