Connection to SharePoint APIs using Hybrid Mobile application
I am working on a mobile hybrid application, where am trying to connect to
a sharepoint website using apis it provide. Basically I want to connect
and access some sharepoint data. After so much of googling I am atlast
able to login to Office 365 using below piece of code.
$.ajax({
'url': 'https://login.microsoftonline.com/extSTS.srf',
dataType: 'text',
type:'POST',
'data': '<s:Envelope
xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:a="http://www.w3.org/2005/08/addressing"
xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><s:Header><a:Action
s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action><a:MessageID>urn:uuid:40c1407d-b2a4-4e05-8248-8a92b71102b6</a:MessageID><a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo><a:To
s:mustUnderstand="1">https://login.microsoftonline.com/extSTS.srf</a:To><o:Security
s:mustUnderstand="1"
xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><u:Timestamp
u:Id="_0"><u:Created>2012-07-26T16:13:00.622Z</u:Created><u:Expires>2012-07-26T16:18:00.622Z</u:Expires></u:Timestamp><o:UsernameToken
u:Id="uuid-69882db9-2d6b-45d3-b016-c2156cb6c01d-1"><o:Username>myusernameisinhere</o:Username><o:Password
Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">mysharepointpasswordisinhere</o:Password></o:UsernameToken></o:Security></s:Header><s:Body><t:RequestSecurityToken
xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust"><wsp:AppliesTo
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"><a:EndpointReference><a:Address>https://somethingonline.sharepoint.com/_forms/default.aspx?wa=wsignin1.0</a:Address></a:EndpointReference></wsp:AppliesTo><t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey</t:KeyType><t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType><t:TokenType>urn:oasis:names:tc:SAML:1.0:assertion</t:TokenType></t:RequestSecurityToken></s:Body></s:Envelope>',
headers: {
Accept : "application/soap+xml; charset=utf-8"
},
success: function(result, textStatus, jqXHR) {
document.body.innerHTML = result;
var xmlDoc = $.parseXML( result );
var xml = $( xmlDoc )
var binToken = xml.find("BinarySecurityToken").text();
callsomeFunction(binToken);
},
error:function (jqXHR, textStatus, errorThrown){
console.log(errorThrown+'error login:' + jqXHR.responseText);
},
complete:function(jqXHR, textStatus) {
console.log('login completed ' + textStatus);
}
});
Now I have a binToken (which I am getting successfully) and I am using it
to call an api, as this,
function callsomeFunction(binToken) {
var domain = "myurlishere";
var url = domain + "_api/web/GetFolderByServerRelativeUrl('PDF')";
$.support.cors = true;
$.ajax({
'url': url,
dataType: 'text',
type:'POST',
'data':binarysecurityToken,
headers: {
Accept : "application/x-www-form-urlencoded"
},
success: function(result, textStatus, jqXHR) {
alert('done wsignin ' + result);
},
error:function (jqXHR, textStatus, errorThrown){
alert('error wsignin:' + jqXHR.responseText);
},
complete:function(jqXHR, textStatus) {
alert('complete wsignin ' + textStatus); }
});
}
So, the output of this is an error with no responseText. Can anybody
please tell me what I am doing wrong in here?
No comments:
Post a Comment