Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Outlook Mac App auth token mismatch

I am implementing an add-in for Outlook, the add-in gets an attachment and sends it to my server for processing. It works flawlessly on https://outlook.office.com but fails to run Outlook 2016 for Mac.

Here is the API I am trying to access:

var getMessageUrl =Office.context.mailbox.restUrl + '/v2.0/me/messages/' +
    {messageID} + "/attachments/" + {attachmentID};

var attachmentID = Office.context.mailbox.item.attachments[0].id;
var messageID = getItemRestId();

$.ajax({
    url: getMessageUrl,
    dataType: 'json',
    headers: {
        'Authorization': 'Bearer ' + outlookToken
    }
}).done(function 1(response) {
    //upload the blob to my server
}).fail(function (error) {
    //call authorise to get a new token
});

function getItemRestId() {
    if (Office.context.mailbox.diagnostics.hostName === 'OutlookIOS') {
        // itemId is already REST-formatted
        return Office.context.mailbox.item.itemId;
    } else {
        // Convert to an item ID for API v2.0
        return Office.context.mailbox.convertToRestId(
            Office.context.mailbox.item.itemId,
            Office.MailboxEnums.RestVersion.v2_0
        );
    }
}

Using Outlook 2016 for Mac, I get a 401 from the above API.

Also, the auth_token I get from calling getCallbackTokenAsync on Outlook 2016 for Mac is different than the one I get in a browser:

Office.context.mailbox.getCallbackTokenAsync({isRest: true}, function (result) {
    if (result.status === "succeeded") {
        //save result.value
    } 
    else {
        //error condition
    }
});

The values in my manifest are:

<Set Name="MailBox" MinVersion="1.3"/>
<Permissions>ReadWriteMailbox</Permissions>

Can someone point out what I am doing wrong here?

UPDATE As per Jason's suggestion, I checked the token I received on jwt.io The versions of the token are different on the browser and on the mac app.

On the Browser: "ver": "Exchange.Callback.V2" On the Mac App: "ver": "Exchange.Callback.V1" 

How do I get the outlook_mac_app to return v2 of the token?

like image 911
EmptyCup Avatar asked Nov 08 '22 11:11

EmptyCup


1 Answers

I cannot comment, so posting this as an answer.

I was hitting 403 for attachments in Outlook for Mac 2016, not sure if they are related, but you could take a look at it here https://github.com/OfficeDev/outlook-add-in-command-demo/issues/30

like image 69
Abhishek S Jain Avatar answered Nov 15 '22 11:11

Abhishek S Jain