UnAuthorized error with access token generated from Outlook WebAddin












0














I am trying to use access token generated in Outlook Addin to download mail attachments, it is throwing an unauthorized error(401). Looks AccessToken is not valid. Using the accessToken within 5 min after generation in the add-in to make sure to avoid expired code.



Followed steps suggested in Office documentation and created the C# code. My code gist is available here : https://gist.github.com/rajeevprasanna/6b0ba1db1599500a94451958b4f52d79



My add-in manifest is available here which asks ReadWriteMailbox permission : https://gist.github.com/rajeevprasanna/5ef93e3df80f304826742bb81a0b4421#file-addin-manifest-xml-L64



I am experimenting on Office365 Outlook WebClient but I have to work on a uniform solution which works on all outlook instances and office365 and Exchange versions.



Code for extracting access token as suggested here :



let cb = (asyncResult) => {
console.log('asyncResult => '+ R.toString(asyncResult));
};

var options = {
isRest: true,
asyncContext: { message: 'Hello World!' }
};
Office.context.mailbox.getCallbackTokenAsync(options, cb);


Using the value filed of the callback response as accessToken while making API call.
sample getCallbackTokenAsync response :



{
"asyncContext": {
"message": "Hello World!"
},
"status": "succeeded",
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImthME5Hb19aNUkwRms1MXpKblZjT2tHbzFvbyJ9.eyJzbXRwIjoic3JpbmlAeGVub3Z1cy1hbWVyaWNhbmEuY29tIiwidmVyIjoiRXhjaGFuZ2UuQ2FsbGJhY2suVjIiLCJhcHBpZCI6IjAwMDAwMDAyLTAwMDAtMGZmMS1jZTAwLTAwMDAwMDAwMDAwMCIsImRlcGxveW1lbnRpZCI6IiIsInRpZCI6Imhvc3RpbmdjbG91ZGFwcC5uZXQiLCJhY3IiOiIxIiwiYXBwaWRhY3IiOiIwIiwic2NwIjoiTWFpbC5SZWFkV3JpdGUgTWFpbC5TZW5kIENhbGVuZGFycy5SZWFkV3JpdGUgQ29udGFjdHMuUmVhZFdyaXRlIiwiaXNzIjoiMDAwMDAwMDItMDAwMC0wZmYxLWNlMDAtMDAwMDAwMDAwMDAwIiwiYXVkIjoiaHR0cHM6Ly93ZWJtYWlsLmhvc3RpbmdjbG91ZGFwcC5jb20iLCJleHAiOjE1NDI4NzcwMDMsIm5iZiI6MTU0Mjg3NjEwM30.c3sknGGbw1Jrip9Ke1AcLyRL-6VnWSSWTGrwmeo6Z7xwBfKD3ppNkSqb4cVZIzuV-8udQps2abQ9scPMn0DNRbFRUNlBfkhHUqR2_JHrMcMptL6ZqF-a7_-gOMcBSgNdUCk5mhGDJs9qiEiM47thv5HZC97k-aYZ-iyU8N-8SgMNDc8vjBdS2nPSKp6FgQfezmjxADT-mbflxNUIwUDfOAys2l8v_Qw30t3LDca2AMmHyK3GbEaXejdO4muzC-ZrRMUVThIfFsMs0x67E2aY--lxSwDmrfcEnXODW0_J72RtFNDV5wjxf1QH6-xfP0A34qbUlmVnjjiCeYCeCCtNEg"
}


After doing some trails and comparing with an example project, i found the error seems to be with permission type ReadWriteMailbox. I am able to fetch attachments if query is done with permission type ReadItem or ReadWriteItem










share|improve this question




















  • 1




    Which client are you trying this from - Outlook Desktop, Web or Mac? Is your exchange backend on Office365 or is it On-Prem?
    – Outlook Add-ins Team - MSFT
    Nov 22 '18 at 0:02










  • @OutlookAdd-insTeam-MSFT updated the question with details you asked.
    – Rajeev
    Nov 22 '18 at 7:00






  • 1




    can you run the sample code at this link to see if succeeds in your add-in? Please use an e-mail that contains a single attachment. The attachment should be a plain text file attachment. Here's the link : gist.github.com/exextoc/472f3c261d654e0eeacd10cad7e0c658
    – Outlook Add-ins Team - MSFT
    Dec 11 '18 at 3:09












  • @OutlookAdd-insTeam-MSFT, This solution is working. but it will not support in old outlook version where isRest is not supported. how to handle those cases?
    – Rajeev
    Dec 12 '18 at 10:27








  • 1




    For clients that do not support isRest, we recommend using EWS instead to retrieve attachments.In your call to getcallbacktokenasync do not pass in isRest(it would default to false) and give you a token you can use against EWS.
    – Outlook Add-ins Team - MSFT
    Dec 18 '18 at 19:44
















0














I am trying to use access token generated in Outlook Addin to download mail attachments, it is throwing an unauthorized error(401). Looks AccessToken is not valid. Using the accessToken within 5 min after generation in the add-in to make sure to avoid expired code.



Followed steps suggested in Office documentation and created the C# code. My code gist is available here : https://gist.github.com/rajeevprasanna/6b0ba1db1599500a94451958b4f52d79



My add-in manifest is available here which asks ReadWriteMailbox permission : https://gist.github.com/rajeevprasanna/5ef93e3df80f304826742bb81a0b4421#file-addin-manifest-xml-L64



I am experimenting on Office365 Outlook WebClient but I have to work on a uniform solution which works on all outlook instances and office365 and Exchange versions.



Code for extracting access token as suggested here :



let cb = (asyncResult) => {
console.log('asyncResult => '+ R.toString(asyncResult));
};

var options = {
isRest: true,
asyncContext: { message: 'Hello World!' }
};
Office.context.mailbox.getCallbackTokenAsync(options, cb);


Using the value filed of the callback response as accessToken while making API call.
sample getCallbackTokenAsync response :



{
"asyncContext": {
"message": "Hello World!"
},
"status": "succeeded",
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImthME5Hb19aNUkwRms1MXpKblZjT2tHbzFvbyJ9.eyJzbXRwIjoic3JpbmlAeGVub3Z1cy1hbWVyaWNhbmEuY29tIiwidmVyIjoiRXhjaGFuZ2UuQ2FsbGJhY2suVjIiLCJhcHBpZCI6IjAwMDAwMDAyLTAwMDAtMGZmMS1jZTAwLTAwMDAwMDAwMDAwMCIsImRlcGxveW1lbnRpZCI6IiIsInRpZCI6Imhvc3RpbmdjbG91ZGFwcC5uZXQiLCJhY3IiOiIxIiwiYXBwaWRhY3IiOiIwIiwic2NwIjoiTWFpbC5SZWFkV3JpdGUgTWFpbC5TZW5kIENhbGVuZGFycy5SZWFkV3JpdGUgQ29udGFjdHMuUmVhZFdyaXRlIiwiaXNzIjoiMDAwMDAwMDItMDAwMC0wZmYxLWNlMDAtMDAwMDAwMDAwMDAwIiwiYXVkIjoiaHR0cHM6Ly93ZWJtYWlsLmhvc3RpbmdjbG91ZGFwcC5jb20iLCJleHAiOjE1NDI4NzcwMDMsIm5iZiI6MTU0Mjg3NjEwM30.c3sknGGbw1Jrip9Ke1AcLyRL-6VnWSSWTGrwmeo6Z7xwBfKD3ppNkSqb4cVZIzuV-8udQps2abQ9scPMn0DNRbFRUNlBfkhHUqR2_JHrMcMptL6ZqF-a7_-gOMcBSgNdUCk5mhGDJs9qiEiM47thv5HZC97k-aYZ-iyU8N-8SgMNDc8vjBdS2nPSKp6FgQfezmjxADT-mbflxNUIwUDfOAys2l8v_Qw30t3LDca2AMmHyK3GbEaXejdO4muzC-ZrRMUVThIfFsMs0x67E2aY--lxSwDmrfcEnXODW0_J72RtFNDV5wjxf1QH6-xfP0A34qbUlmVnjjiCeYCeCCtNEg"
}


After doing some trails and comparing with an example project, i found the error seems to be with permission type ReadWriteMailbox. I am able to fetch attachments if query is done with permission type ReadItem or ReadWriteItem










share|improve this question




















  • 1




    Which client are you trying this from - Outlook Desktop, Web or Mac? Is your exchange backend on Office365 or is it On-Prem?
    – Outlook Add-ins Team - MSFT
    Nov 22 '18 at 0:02










  • @OutlookAdd-insTeam-MSFT updated the question with details you asked.
    – Rajeev
    Nov 22 '18 at 7:00






  • 1




    can you run the sample code at this link to see if succeeds in your add-in? Please use an e-mail that contains a single attachment. The attachment should be a plain text file attachment. Here's the link : gist.github.com/exextoc/472f3c261d654e0eeacd10cad7e0c658
    – Outlook Add-ins Team - MSFT
    Dec 11 '18 at 3:09












  • @OutlookAdd-insTeam-MSFT, This solution is working. but it will not support in old outlook version where isRest is not supported. how to handle those cases?
    – Rajeev
    Dec 12 '18 at 10:27








  • 1




    For clients that do not support isRest, we recommend using EWS instead to retrieve attachments.In your call to getcallbacktokenasync do not pass in isRest(it would default to false) and give you a token you can use against EWS.
    – Outlook Add-ins Team - MSFT
    Dec 18 '18 at 19:44














0












0








0


2





I am trying to use access token generated in Outlook Addin to download mail attachments, it is throwing an unauthorized error(401). Looks AccessToken is not valid. Using the accessToken within 5 min after generation in the add-in to make sure to avoid expired code.



Followed steps suggested in Office documentation and created the C# code. My code gist is available here : https://gist.github.com/rajeevprasanna/6b0ba1db1599500a94451958b4f52d79



My add-in manifest is available here which asks ReadWriteMailbox permission : https://gist.github.com/rajeevprasanna/5ef93e3df80f304826742bb81a0b4421#file-addin-manifest-xml-L64



I am experimenting on Office365 Outlook WebClient but I have to work on a uniform solution which works on all outlook instances and office365 and Exchange versions.



Code for extracting access token as suggested here :



let cb = (asyncResult) => {
console.log('asyncResult => '+ R.toString(asyncResult));
};

var options = {
isRest: true,
asyncContext: { message: 'Hello World!' }
};
Office.context.mailbox.getCallbackTokenAsync(options, cb);


Using the value filed of the callback response as accessToken while making API call.
sample getCallbackTokenAsync response :



{
"asyncContext": {
"message": "Hello World!"
},
"status": "succeeded",
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImthME5Hb19aNUkwRms1MXpKblZjT2tHbzFvbyJ9.eyJzbXRwIjoic3JpbmlAeGVub3Z1cy1hbWVyaWNhbmEuY29tIiwidmVyIjoiRXhjaGFuZ2UuQ2FsbGJhY2suVjIiLCJhcHBpZCI6IjAwMDAwMDAyLTAwMDAtMGZmMS1jZTAwLTAwMDAwMDAwMDAwMCIsImRlcGxveW1lbnRpZCI6IiIsInRpZCI6Imhvc3RpbmdjbG91ZGFwcC5uZXQiLCJhY3IiOiIxIiwiYXBwaWRhY3IiOiIwIiwic2NwIjoiTWFpbC5SZWFkV3JpdGUgTWFpbC5TZW5kIENhbGVuZGFycy5SZWFkV3JpdGUgQ29udGFjdHMuUmVhZFdyaXRlIiwiaXNzIjoiMDAwMDAwMDItMDAwMC0wZmYxLWNlMDAtMDAwMDAwMDAwMDAwIiwiYXVkIjoiaHR0cHM6Ly93ZWJtYWlsLmhvc3RpbmdjbG91ZGFwcC5jb20iLCJleHAiOjE1NDI4NzcwMDMsIm5iZiI6MTU0Mjg3NjEwM30.c3sknGGbw1Jrip9Ke1AcLyRL-6VnWSSWTGrwmeo6Z7xwBfKD3ppNkSqb4cVZIzuV-8udQps2abQ9scPMn0DNRbFRUNlBfkhHUqR2_JHrMcMptL6ZqF-a7_-gOMcBSgNdUCk5mhGDJs9qiEiM47thv5HZC97k-aYZ-iyU8N-8SgMNDc8vjBdS2nPSKp6FgQfezmjxADT-mbflxNUIwUDfOAys2l8v_Qw30t3LDca2AMmHyK3GbEaXejdO4muzC-ZrRMUVThIfFsMs0x67E2aY--lxSwDmrfcEnXODW0_J72RtFNDV5wjxf1QH6-xfP0A34qbUlmVnjjiCeYCeCCtNEg"
}


After doing some trails and comparing with an example project, i found the error seems to be with permission type ReadWriteMailbox. I am able to fetch attachments if query is done with permission type ReadItem or ReadWriteItem










share|improve this question















I am trying to use access token generated in Outlook Addin to download mail attachments, it is throwing an unauthorized error(401). Looks AccessToken is not valid. Using the accessToken within 5 min after generation in the add-in to make sure to avoid expired code.



Followed steps suggested in Office documentation and created the C# code. My code gist is available here : https://gist.github.com/rajeevprasanna/6b0ba1db1599500a94451958b4f52d79



My add-in manifest is available here which asks ReadWriteMailbox permission : https://gist.github.com/rajeevprasanna/5ef93e3df80f304826742bb81a0b4421#file-addin-manifest-xml-L64



I am experimenting on Office365 Outlook WebClient but I have to work on a uniform solution which works on all outlook instances and office365 and Exchange versions.



Code for extracting access token as suggested here :



let cb = (asyncResult) => {
console.log('asyncResult => '+ R.toString(asyncResult));
};

var options = {
isRest: true,
asyncContext: { message: 'Hello World!' }
};
Office.context.mailbox.getCallbackTokenAsync(options, cb);


Using the value filed of the callback response as accessToken while making API call.
sample getCallbackTokenAsync response :



{
"asyncContext": {
"message": "Hello World!"
},
"status": "succeeded",
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImthME5Hb19aNUkwRms1MXpKblZjT2tHbzFvbyJ9.eyJzbXRwIjoic3JpbmlAeGVub3Z1cy1hbWVyaWNhbmEuY29tIiwidmVyIjoiRXhjaGFuZ2UuQ2FsbGJhY2suVjIiLCJhcHBpZCI6IjAwMDAwMDAyLTAwMDAtMGZmMS1jZTAwLTAwMDAwMDAwMDAwMCIsImRlcGxveW1lbnRpZCI6IiIsInRpZCI6Imhvc3RpbmdjbG91ZGFwcC5uZXQiLCJhY3IiOiIxIiwiYXBwaWRhY3IiOiIwIiwic2NwIjoiTWFpbC5SZWFkV3JpdGUgTWFpbC5TZW5kIENhbGVuZGFycy5SZWFkV3JpdGUgQ29udGFjdHMuUmVhZFdyaXRlIiwiaXNzIjoiMDAwMDAwMDItMDAwMC0wZmYxLWNlMDAtMDAwMDAwMDAwMDAwIiwiYXVkIjoiaHR0cHM6Ly93ZWJtYWlsLmhvc3RpbmdjbG91ZGFwcC5jb20iLCJleHAiOjE1NDI4NzcwMDMsIm5iZiI6MTU0Mjg3NjEwM30.c3sknGGbw1Jrip9Ke1AcLyRL-6VnWSSWTGrwmeo6Z7xwBfKD3ppNkSqb4cVZIzuV-8udQps2abQ9scPMn0DNRbFRUNlBfkhHUqR2_JHrMcMptL6ZqF-a7_-gOMcBSgNdUCk5mhGDJs9qiEiM47thv5HZC97k-aYZ-iyU8N-8SgMNDc8vjBdS2nPSKp6FgQfezmjxADT-mbflxNUIwUDfOAys2l8v_Qw30t3LDca2AMmHyK3GbEaXejdO4muzC-ZrRMUVThIfFsMs0x67E2aY--lxSwDmrfcEnXODW0_J72RtFNDV5wjxf1QH6-xfP0A34qbUlmVnjjiCeYCeCCtNEg"
}


After doing some trails and comparing with an example project, i found the error seems to be with permission type ReadWriteMailbox. I am able to fetch attachments if query is done with permission type ReadItem or ReadWriteItem







exchangewebservices outlook-addin office-js outlook-web-addins






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 10:44

























asked Nov 21 '18 at 11:46









Rajeev

1,73242843




1,73242843








  • 1




    Which client are you trying this from - Outlook Desktop, Web or Mac? Is your exchange backend on Office365 or is it On-Prem?
    – Outlook Add-ins Team - MSFT
    Nov 22 '18 at 0:02










  • @OutlookAdd-insTeam-MSFT updated the question with details you asked.
    – Rajeev
    Nov 22 '18 at 7:00






  • 1




    can you run the sample code at this link to see if succeeds in your add-in? Please use an e-mail that contains a single attachment. The attachment should be a plain text file attachment. Here's the link : gist.github.com/exextoc/472f3c261d654e0eeacd10cad7e0c658
    – Outlook Add-ins Team - MSFT
    Dec 11 '18 at 3:09












  • @OutlookAdd-insTeam-MSFT, This solution is working. but it will not support in old outlook version where isRest is not supported. how to handle those cases?
    – Rajeev
    Dec 12 '18 at 10:27








  • 1




    For clients that do not support isRest, we recommend using EWS instead to retrieve attachments.In your call to getcallbacktokenasync do not pass in isRest(it would default to false) and give you a token you can use against EWS.
    – Outlook Add-ins Team - MSFT
    Dec 18 '18 at 19:44














  • 1




    Which client are you trying this from - Outlook Desktop, Web or Mac? Is your exchange backend on Office365 or is it On-Prem?
    – Outlook Add-ins Team - MSFT
    Nov 22 '18 at 0:02










  • @OutlookAdd-insTeam-MSFT updated the question with details you asked.
    – Rajeev
    Nov 22 '18 at 7:00






  • 1




    can you run the sample code at this link to see if succeeds in your add-in? Please use an e-mail that contains a single attachment. The attachment should be a plain text file attachment. Here's the link : gist.github.com/exextoc/472f3c261d654e0eeacd10cad7e0c658
    – Outlook Add-ins Team - MSFT
    Dec 11 '18 at 3:09












  • @OutlookAdd-insTeam-MSFT, This solution is working. but it will not support in old outlook version where isRest is not supported. how to handle those cases?
    – Rajeev
    Dec 12 '18 at 10:27








  • 1




    For clients that do not support isRest, we recommend using EWS instead to retrieve attachments.In your call to getcallbacktokenasync do not pass in isRest(it would default to false) and give you a token you can use against EWS.
    – Outlook Add-ins Team - MSFT
    Dec 18 '18 at 19:44








1




1




Which client are you trying this from - Outlook Desktop, Web or Mac? Is your exchange backend on Office365 or is it On-Prem?
– Outlook Add-ins Team - MSFT
Nov 22 '18 at 0:02




Which client are you trying this from - Outlook Desktop, Web or Mac? Is your exchange backend on Office365 or is it On-Prem?
– Outlook Add-ins Team - MSFT
Nov 22 '18 at 0:02












@OutlookAdd-insTeam-MSFT updated the question with details you asked.
– Rajeev
Nov 22 '18 at 7:00




@OutlookAdd-insTeam-MSFT updated the question with details you asked.
– Rajeev
Nov 22 '18 at 7:00




1




1




can you run the sample code at this link to see if succeeds in your add-in? Please use an e-mail that contains a single attachment. The attachment should be a plain text file attachment. Here's the link : gist.github.com/exextoc/472f3c261d654e0eeacd10cad7e0c658
– Outlook Add-ins Team - MSFT
Dec 11 '18 at 3:09






can you run the sample code at this link to see if succeeds in your add-in? Please use an e-mail that contains a single attachment. The attachment should be a plain text file attachment. Here's the link : gist.github.com/exextoc/472f3c261d654e0eeacd10cad7e0c658
– Outlook Add-ins Team - MSFT
Dec 11 '18 at 3:09














@OutlookAdd-insTeam-MSFT, This solution is working. but it will not support in old outlook version where isRest is not supported. how to handle those cases?
– Rajeev
Dec 12 '18 at 10:27






@OutlookAdd-insTeam-MSFT, This solution is working. but it will not support in old outlook version where isRest is not supported. how to handle those cases?
– Rajeev
Dec 12 '18 at 10:27






1




1




For clients that do not support isRest, we recommend using EWS instead to retrieve attachments.In your call to getcallbacktokenasync do not pass in isRest(it would default to false) and give you a token you can use against EWS.
– Outlook Add-ins Team - MSFT
Dec 18 '18 at 19:44




For clients that do not support isRest, we recommend using EWS instead to retrieve attachments.In your call to getcallbacktokenasync do not pass in isRest(it would default to false) and give you a token you can use against EWS.
– Outlook Add-ins Team - MSFT
Dec 18 '18 at 19:44

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53411354%2funauthorized-error-with-access-token-generated-from-outlook-webaddin%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53411354%2funauthorized-error-with-access-token-generated-from-outlook-webaddin%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python