0

I am trying to access SharePoint online using REST API's remotely. Office 365 Smart links are enabled for the site. As per this blog I don't receive wsse\\:BinarySecurityToken in the response. My code is as follows:

$.ajax({
'url': 'https://sts.something.com/adfs/ls/?&wa=wsignin1.0&wtrealm=urn:federation:MicrosoftOnline&wctx=wa%3Dwsignin1.0%26rpsnv%3D4%26ct%3D1417151170%26rver%3D6.1.6206.0%26wp%3DMBI%26wreply%3Dhttps:%252F%252Fsomethingonline.sharepoint.com%252F_forms%252Fdefault.aspx%26lc%3D16393%26id%3D500046%26bk%3D1417151171%26LoginOptions%3D3',
           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>userid@something.com</o:Username><o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">*********</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://somthingonline.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) {
        console.log('done in login ');
        console.log('result '+result);
        var xmlDoc = $.parseXML( result );
        console.log("xmlDoc:"+xmlDoc);
        var xml = $( xmlDoc )
        console.log("xml:"+xml);
        var binToken= xml.find( "wsse\\:BinarySecurityToken" ).text();
        console.log("Binary Token:"+binToken);
                                            alert("Binary Token:"+binToken);

        //  alert(  localStorage.getItem('BinaryToken') );
        wsignin(binToken);
    },
    error:function (jqXHR, textStatus, errorThrown){
        console.log(errorThrown+'error login:' + jqXHR.responseText);
    },
    complete:function(jqXHR, textStatus) {
        console.log('login completed ' + textStatus);
    }
});

My response in fiddler is as follows:

<html><head><title>Working...</title></head><body><form method="POST" name="hiddenform" action="https://login.microsoftonline.com/login.srf"><input type="hidden" name="wa" value="wsignin1.0" /><input type="hidden" name="wresult" value="&lt;t:RequestSecurityTokenResponse xmlns:t=&quot;http://schemas.xmlsoap.org/ws/2005/02/trust&quot;>&lt;t:Lifetime>&lt;wsu:Created xmlns:wsu=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd&quot;>2014-11-28T18:37:25.272Z&lt;/wsu:Created>&lt;wsu:Expires xmlns:wsu=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd&quot;>2014-11-28T19:37:25.272Z&lt;/wsu:Expires>&lt;/t:Lifetime>&lt;wsp:AppliesTo xmlns:wsp=&quot;http://schemas.xmlsoap.org/ws/2004/09/policy&quot;>&lt;wsa:EndpointReference xmlns:wsa=&quot;http://www.w3.org/2005/08/addressing&quot;>&lt;wsa:Address>urn:federation:MicrosoftOnline&lt;/wsa:Address>&lt;/wsa:EndpointReference>&lt;/wsp:AppliesTo>&lt;t:RequestedSecurityToken>&lt;saml:Assertion MajorVersion=&quot;1&quot; MinorVersion=&quot;1&quot; AssertionID=&quot;_7f55172b-43f9-466c-bede-436d794119e2&quot; Issuer=&quot;http://sts.something.com/adfs/services/trust&quot; IssueInstant=&quot;2014-11-28T18:37:25.274Z&quot; xmlns:saml=&quot;urn:oasis:names:tc:SAML:1.0:assertion&quot;>&lt;saml:Conditions NotBefore=&quot;2014-11-28T18:37:25.272Z&quot; NotOnOrAfter=&quot;2014-11-28T19:37:25.272Z&quot;>&lt;saml:AudienceRestrictionCondition>&lt;saml:Audience>urn:federation:MicrosoftOnline&lt;/saml:Audience>&lt;/saml:AudienceRestrictionCondition>&lt;/saml:Conditions>&lt;saml:AttributeStatement>&lt;saml:Subject>&lt;saml:NameIdentifier Format=&quot;urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified&quot;>ddcNR0t/6kWEAp4knvEteA==&lt;/saml:NameIdentifier>&lt;saml:SubjectConfirmation>&lt;saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer&lt;/saml:ConfirmationMethod>&lt;/saml:SubjectConfirmation>&lt;/saml:Subject>&lt;saml:Attribute AttributeName=&quot;UPN&quot; AttributeNamespace=&quot;http://schemas.xmlsoap.org/claims&quot;>&lt;saml:AttributeValue>userid@something.COM&lt;/saml:AttributeValue>&lt;/saml:Attribute>&lt;saml:Attribute AttributeName=&quot;ImmutableID&quot; AttributeNamespace=&quot;http://schemas.microsoft.com/LiveID/Federation/2008/05&quot;>&lt;saml:AttributeValue>ddcNR0t/6kWEAp4knvEteA==&lt;/saml:AttributeValue>&lt;/saml:Attribute>&lt;/saml:AttributeStatement>&lt;saml:AuthenticationStatement AuthenticationMethod=&quot;urn:oasis:names:tc:SAML:1.0:am:password&quot; AuthenticationInstant=&quot;2014-11-28T18:37:24.943Z&quot;>&lt;saml:Subject>&lt;saml:NameIdentifier Format=&quot;urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified&quot;>ddcNR0t/6kWEAp4knvEteA==&lt;/saml:NameIdentifier>&lt;saml:SubjectConfirmation>&lt;saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer&lt;/saml:ConfirmationMethod>&lt;/saml:SubjectConfirmation>&lt;/saml:Subject>&lt;/saml:AuthenticationStatement>&lt;Signature xmlns=&quot;http://www.w3.org/2000/09/xmldsig#&quot;>&lt;SignedInfo>&lt;CanonicalizationMethod Algorithm=&quot;http://www.w3.org/2001/10/xml-exc-c14n#&quot; />&lt;SignatureMethod Algorithm=&quot;http://www.w3.org/2000/09/xmldsig#rsa-sha1&quot; />&lt;Reference URI=&quot;#_7f55172b-43f9-466c-bede-436d794119e2&quot;>&lt;Transforms>&lt;Transform Algorithm=&quot;http://www.w3.org/2000/09/xmldsig#enveloped-signature&quot; />&lt;Transform Algorithm=&quot;http://www.w3.org/2001/10/xml-exc-c14n#&quot; />&lt;/Transforms>&lt;DigestMethod Algorithm=&quot;http://www.w3.org/2000/09/xmldsig#sha1&quot; />&lt;DigestValue>9Jldbpiqe7ie6Q4R9MBRBL3y3to=&lt;/DigestValue>&lt;/Reference>&lt;/SignedInfo>&lt;SignatureValue>geVzxtwW4bSbLRCEUTgIdn3xwZFnyHXLBamGlnudEwBdxpUrtlyUZBD71zpbP85AIuoFTNPsAGwDsknaRa5jhurDIJ2AsR2rsOh8dlnFDEwCK76zldPVXWIVIat255ShMDRLG3dlBDuHN1h8rdBihKrMD2tfS4xJ8KAI1+jwhaeM8/RYIFktCQUhjnUszmiChOfiqSl+a0aitgboGmP9blDrZcEu8UflslAgnmRr0mRg3NP8JoRqhNH/XuqEXNJUihuGmGqK8pwbSQpPGMl2qmBk20F3lliOFXcToQCFHBMY52c4jix2X8yxvFTU5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t;/Signature>&lt;/saml:Assertion>&lt;/t:RequestedSecurityToken>&lt;t:TokenType>urn:oasis:names:tc:SAML:1.0:assertion&lt;/t:TokenType>&lt;t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue&lt;/t:RequestType>&lt;t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey&lt;/t:KeyType>&lt;/t:RequestSecurityTokenResponse>" /><input type="hidden" name="wctx" value="wa=wsignin1.0&amp;rpsnv=4&amp;ct=1417199483&amp;rver=6.1.6206.0&amp;wp=MBI&amp;wreply=https:%2F%2Fsomethingonline.sharepoint.com%2F_forms%2Fdefault.aspx&amp;lc=1033&amp;id=500046&amp;bk=1417199484&amp;LoginOptions=3" /><noscript><p>Script is disabled. Click Submit to continue.</p><input type="submit" value="Submit" /></noscript></form><script language="javascript">window.setTimeout('document.forms[0].submit()', 0);</script></body></html>

I get the above response when I am within the domain else I get the html for custom login page as smart links has been configured. I am not sure if I am posting to the right url.How do I get to to the response with BinarySecurityToken?

1

This issue is resolved .I tracked the requests and responses by SharePointOnlineCredentials class in CSOM using fiddler and followed the same. Reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.