Sharepoint online authentication with Cordova

Hi,

I am having challenges with authenticating my mobile app with SharePoint online. On a button click, i am calling the angualarjs controller below.

I have <script src="scripts/RequestExecutor.js"></script> in my index.html

MobileApp.controller('loginController', function ($scope) {
    $scope.login = function () {
        authenticate();
    }
});

function authenticate() {
var appweburl ="";
    var executor = new SP.RequestExecutor(appweburl );

    var sbody = "<?xml version='1.0' encoding='utf-8'?>\
     <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>\
  <soap:Body>\
    <Login xmlns='http://schemas.microsoft.com/sharepoint/soap/'>\
      <username>[user id]\
      <password>[pwd]</password>\
    </Login>\
  </soap:Body>\
</soap:Envelope>";
    executor.executeAsync(
  {
      url: appweburl +"/_vti_bin/authentication.asmx?op=Login",
      method: "GET",
      headers: {
          Accept: "application/json; odata=verbose",
          Host: 'company.sharepoint.com',
          'Content-Type': 'text/xml; charset=utf-8',
          'Content-Length': length,
          SOAPAction: "http://schemas.microsoft.com/sharepoint/soap/Login"
      },
      data: { sbody },
      success: successHandler,
      error: errorHandler
  }
);

    function successHandler(data) {

        document.getElementById("results").innerHTML =
            announcementsHTML;
    }

    function errorHandler(data, errorCode, errorMessage) {
        alert(errorCode + errorMessage);
       
    }

}

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://.sharepoint.com') does not match the recipient window's origin ('null').SP.RequestExecutor.$F @ RequestExecutor.js:2SP.RequestExecutor.$1b @ RequestExecutor.js:2SP.RequestExecutor.$1x @ RequestExecutor.js:2(anonymous function) @ RequestExecutor.js:2
RequestExecutor.js:2 Sun May 31 2015 11:19:16 GMT+0100 (W. Central Africa Standard Time):Ping timeout
RequestExecutor.js:2 Sun May 31 2015 11:19:16 GMT+0100 (W. Central Africa Standard Time):Ping timeout count = 25
RequestExecutor.js:2 Sun May 31 2015 11:19:16 GMT+0100 (W. Central Africa Standard Time):Send ping again for https://---.sharepoint.com/sites/-team-site/_layouts/15/AppWebProxy.aspx
RequestExecutor.js:2 Sun May 31 2015 11:19:16 GMT+0100 (W. Central Africa Standard Time):Create IFramePingTimeout 42
RequestExecutor.js:2 Sun May 31 2015 11:19:16 GMT+0100 (W. Central Africa Standard Time):RequestExecutor.PostMessage.Message: {"command":"Ping","postMessageId":"SP.RequestExecutor27"}
RequestExecutor.js:2 Sun May 31 2015 11:19:16 GMT+0100 (W. Central Africa Standard Time):RequestExecutor.PostMessage.Target: https://.sharepoint.com/sites/-team-site/_layouts/15/AppWebProxy.aspx


I am new to SharePoint, any help will be appreciated

May 31st, 2015 7:00am

This part of the error has the issue: "Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://.sharepoint.com') does not match the recipient window's origin ('null')"

Based on this I would say the variable "appweburl" is not getting set in your code. You have this line:

var appweburl ="";

Not sure if you removed that for this post, of if its not being set at all. Try hard coding it throughout and see if it works, then move it back to a variable.

Also, try searching the web for "Failed to execute 'postMessage' on 'DOMWindow': The target origin provided" and you'll get some different posts about people seeing this message.

Good luck!

Free Windows Admin Tool Kit Click here and download it now
May 31st, 2015 8:51am

Thanks Brandon,

the actual code has the appweburl hard coded in it.

i am thinking it the same same issue as explained here https://msdn.microsoft.com/library/jj612823%28v=office.15%29

thanks


  • Edited by Manex- 17 hours 58 minutes ago
May 31st, 2015 9:08am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics