Authenticate in Sharepoint online via Rest api + AngularJS [duplicate]

3

I'm trying to create an application using Visual Studio 2015, Cordova + AngularJS.

My need today is to authenticate in Sharepoint and consume the Web Services. I've made several authentication attempts, but I'm not succeeding.

(function () {

var app = angular.module('spContact', ['ngRoute']);

app.factory('spAuthService', function ($http, $q) {

    var authenticate = function (userId, password, url) {

        var signInurl = 'https://' + url + '/_forms/default.aspx?wa=wsignin1.0';
        var deferred = $q.defer();
        var message = getSAMLRequest(userId, password, signInurl);

        $http({
            method: 'POST',
            url: 'https://login.microsoftonline.com/extSTS.srf',
            data: message,
            headers: {
                'Content-Type': "text/xml; charset=\"utf-8\""
            }
        }).success(function (data) {
            getBearerToken(data, signInurl).then(function (data) {
                deferred.resolve(data);
            }, function (data) {
                deferred.reject(data)
            })
        });

        return deferred.promise;
    };

    return {
        authenticate: authenticate
    };

    function getSAMLRequest(userID, password, url) {
        return 'envelope';
    }

    function getBearerToken(result, url) {

        var deferred = $q.defer();
        var securityToken = $($.parseXML(result)).find("BinarySecurityToken").text();
        if (securityToken.length == 0) {
            deferred.reject();
        }
        else {
            $http({
                method: 'POST',
                url: url,
                data: securityToken,
                headers: {
                    Accept: "application/json;odata=verbose"
                }
            }).success(function (data) {
                deferred.resolve(data);
            }).error(function () {
                deferred.reject();
            });
        }

        return deferred.promise;
    }
});

})();

Can someone help me?

    
asked by anonymous 21.10.2015 / 22:04

1 answer

0

It was a cross-domain problem ( login.microsoftonline.com is an external domain, of course). More details on resolving this type of issue can be found at Phonegap at Enable CORS via JavaScript ( Phonegap ) .

    
03.12.2015 / 18:40