Search code examples
outlookmicrosoft-graph-apioffice-jsoutlook-addinoutlook-web-addins

How to get GRAPH API token in office.js to use in Online/desktop outlook?


I am developing add-in based on office.js for Outlook and desktop one. In addin I want option to saved previusly emails(their id ) open them in new window by click. For that I need to make identifiers immutable. To make identifiers immutable I need to use GRAPH API. More preferably this POST method to transform dynamic IDs to constant ones.

https://graph.microsoft.com/v1.0/me/translateExchangeIds

But here is a problem to use this method I need authorization token to be passed in headers of that request.
Question is how to get needed GRAPH API authorization token using office.js functional?

What tokens I tried:

  • Using Office.auth.getAccessToken() but as result of request I got error in my online outlook - API is not supported in this platform.
  • Using Office.auth.getAccessToken() but I got same result - API is not supported in this platform
  • Using Office.context.mailbox.getCallbackTokenAsync() yeah I got as resultat token, but if you pass this token in GRAPHS API request headers then it throws error in console what request was bad (bad Authorization token)

Solution

  • To understand how the Single Sign-On (SSO) works in Office add-ins I'd suggest creating a new sample add-in and run the code under the debugger. The process is documented in the Single sign-on (SSO) quick start guide. Also you may find the sample add-in which uses SSO helpful.

    The getAccessToken method calls the Azure Active Directory V 2.0 endpoint to get an access token to your add-in's web application. Enables add-ins to identify users. Server-side code can use this token to access Microsoft Graph for the add-in's web application by using the "on behalf of" OAuth flow. This API requires a single sign-on configuration that bridges the add-in to an Azure application. Office users sign-in with Organizational Accounts and Microsoft Accounts. Microsoft Azure returns tokens intended for both user account types to access resources in the Microsoft Graph.