Using Identity 1.1 in an Outlook Addin (Single Sign On). I get InvalidAuthenticationToken when trying to call a OneDrive API RRS feed

  • Question

  • Hi!

    I registered an application in the Azure server following exactly the instructions that were in the official documentation. 

    In the Office Addin, in the XML file I have (I know, there are more things than probably needed):


    So in the Addin I well get the token... but when I call:

            function uploadSampleFile() {
                console.log('Uploading file using token ' + tokenGot);
                var xmlHttp = new XMLHttpRequest();
                //xmlHttp.timeout = 10000;
                xmlHttp.onreadystatechange = function () {
                    if (this.readyState == 4 && (this.status == 200 || this.status == 201)) {
                        console.log('UPLOAD: ' + this.responseText);
                        document.getElementById('UploadStatus').innerHTML = 'File successfully uploaded to Attachments/FromSample.txt';
                    } else if (this.readyState == 4) {
                        console.log('UPLOAD: ' + this.responseText);
                        document.getElementById('UploadStatus').innerHTML = 'Error while uploading. Status=' + this.status + '(' + this.responseText+')';
      "PUT", "", true); // true for asynchronous
                xmlHttp.setRequestHeader('Authorization', 'Bearer ' + tokenGot);
                document.getElementById('UploadStatus').innerHTML = 'Uploading file to Attachments/FromSample.txt';
                xmlHttp.send("This is the internal content to test");

    I get tbhe InvalidAuthenticationToken  error.

    I think I have to configure something in the server so the token I get can be used for OneDrive for Business... but I granted all possible permissions. If for example I get the token using another different way (e.g. MSAL.js) then using the exact same App I can upload it... so it's not really linked to the API Permissions but it seems like if the token the Identity 1.1 library returns cannot be used for :"

    Any idea??


    Monday, October 21, 2019 5:31 PM