Search code examples
single-sign-onoffice-jsoffice-addinsword-addinsword-web-addins

Switching account not working with Office addin with Single Sign on


I am using the yeoman generator to generate the 'Office Add-in Task Pane project supporting single sign-on (localhost)' example. When I run the example in Word the user name and email are pasted into the document as expected. But when I switch account by using the button in the upper-right corner of Word switch account button the addin is still using the first selected account.

Is there a way to make the addin use the newly selected account without the need to close and open the addin?


Solution

  • The Office host application, Word in your scenario, requests the access token from the Microsoft identity platform for the current user. The Microsoft identity platform returns the access token to Office. Office caches the token on your behalf so that future calls to getAccessToken simply return the cached token. You must restart the host application to clear the cached token.

    As a best security practice, always call getAccessToken when you need an access token. Office will cache it for you. Don't cache or store the access token using your own code.

    The Office JavaScript API (OfficeJS) doesn't provide any property or method to refresh the token or mark it expired. So, I'd suggest posting this as a bug to the OfficeJS repo at GitHub.

    Note, you can post or vote for an existing feature request on Tech Community where they are considered when the Office dev team goes through the planning process.