Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Cross-Platform Mobile Application for SharePoint 2013

I want to make a simple CRUD Cross-Platform Mobile Application for my SharePoint server at work. I'm using PhoneGap to deal with the cross-platform coding - as a result my code will be in HTML, CSS, and JavaScript.

The main roadblock I have had is authenticating with my SharePoint server. Many people online have successfully used AJAX calls, however I receive the following error:

XMLHttpRequest cannot load http://<DOMAIN>/_vti_bin/authentication.asmx. The request was redirected to 'http://<DOMAIN>/_layouts/15/error.aspx?ErrorText=Request%20format%20is%20unrecognized%2E', which is disallowed for cross-origin requests that require preflight. 

The following is my JavaScript code:

function Authenticate() {
    $.support.cors = true;
    $.mobile.allowCrossDomainPages = true;

    $("#topnavcontent").append("Creating SOAP envelope...</br>");

    var soapEnv = "<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>USERNAME</username>" +
    "<password>PASSWORD</password>" +
    "</Login>" +
    "</soap:Body>" +
    "</soap:Envelope>";

    $("#topnavcontent").append("Calling authenticate.asmx...</br>");

    $.ajax({
        url: "http://<DOMAIN>/_vti_bin/authentication.asmx",
        type: "POST",
        data: soapEnv,
        complete: authenticationResultSuccess,
        contentType: "text/xml; charset=\"utf-8\"",
        error: authenticationResultError
    });
}

I understand the browser is sending a pre-flight OPTIONS call. The SharePoint site by default does not support OPTIONS calls. Is there any workaround for this, such as disabling this OPTIONS call or a setting in the webconfig on the SharePoint site that will allow the pre-flight through. Thanks in advance for the help.

like image 879
DrEvans Avatar asked Nov 10 '22 13:11

DrEvans


1 Answers

The Office 365 APIs are designed to be used against Mobile Apps and Standalone Web Applications. More details here: http://msdn.microsoft.com/en-us/library/office/dn605892(v=office.15).aspx

Once you have authenticated with Azure AD with the new Office 365 APIs, you can actually use the SharePoint CSOM and REST APIs with the auth bearer.

Have you checked out the Cordova (PhoneGap) project type in Visual Studio 2013? This generates js files when you do Add Connections n the project node in Solution Explorer to connect to the Office 365 APIs.

Very shortly we'll have code samples of the WoodGrove App that was demoed at MS TechEd NA Keynote in http://www.github.com/OfficeDev.

There is currently native Android samples using this API via the Android SDK here https://github.com/OfficeDev/Office-365-SDK-for-Android

like image 186
Jeremy Thake MSFT Avatar answered Nov 14 '22 21:11

Jeremy Thake MSFT