mercredi 4 mars 2015

How to authenticate user in SharePoint Online using rest api



I have a website on SharePoint Online and a website on SharePoint On-premise. From my On-premise website i want to create a new list on my SharePoint Online site.


To authenticate I used the following codes:




var soapRequest =
'<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:xsd="http://ift.tt/tphNwY"
xmlns:soap12="http://ift.tt/18hkEkn">
<soap12:Body>
<Login xmlns="http://ift.tt/rrg8m0">
<username>username@email.com</username>
<password>userpassword</password>
</Login>
</soap12:Body>
</soap12:Envelope>';


And then:




$.ajax({
url: myUrl + "_vti_bin/authentication.asmx?op=Login",
type: "GET",
contentType: "text/xml",
dataType: "json",
data: soapRequest,
success: function (a) {
console.log(a);
},
error: function (a) {
console.log(a);
}
});


As result I get:


XMLHttpRequest cannot load https://myUrl/_vti_bin/authenti…in3!%22%3C/password%3E%3C/Login%3E%3C/soap12:Body%3E%3C/soap12:Envelope%3E. The request was redirected to 'https://myUrl/_layouts/15/error.aspx?ErrorText=Request%20format%20is%20unrecognized%2E', which is disallowed for cross-origin requests that require preflight.


What can I do to avoid the error?


Thank you very much.








0 commentaires:

Enregistrer un commentaire