简体   繁体   中英

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切换帐户按钮 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?

@EugeneAstafiev's answer is correct. To address a couple of other points in your question:

  1. It is expected behavior that that you will still get data from the first user until the access token expires, which is never more than an hour. As Eugene noted, this is because Office caches the token and reuses it until it expires.
  2. The scenario in which a user signs out and another user signs in, without closing the document or even the add-in , is unusual. The add-in infrastructure is designed under the assumption that add-ins are run by the user that opens the document, because that is the user that has access to the document.
  3. There is no way for the add-in to detect at runtime that the user has changed.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM