TL;DR - How do we expire the access token when the user signs out in another tab?
Details:
In the SSO documentation it says:
When to call the method
If your add-in cannot be used when no user is logged into Office, then you should call
getAccessToken
when the add-in launches and passallowSignInPrompt: true
in the options parameter ofgetAccessToken
.
That's nice and clear. But when should we stop using the token? Is there an event we can use to know the user signed out? (I haven't been able to find one.)
I ask because the token continues to work even when the user signs out in another tab. So if we keep the token for any length of time, it leaves scenarios open where the user's account is used incorrectly. For instance:
- User signs in
- User opens the add-in; add-in grabs an access token and keeps it
- User opens another tab
- User signs out of their account in that other tab
- User steps away
- Someone else uses the add-in to do something they shouldn't
I just did that (well, not Step 6), and the access token continued to work in the tab with the add-in. Yes, the user probably should have closed the tab when they signed out. And yes, they shouldn't leave their computer unlocked either. But I'd like to expire the token in that situation.
Here's another that's a bit easier to see happening:
- User signs in
- User opens add-in
- User realizes they need to switch accounts. Since you can't do that in Web Excel, they do it in another tab
- User tries to use the add-in — and it's using the old account, not the one the switched to
We were just acquiring the token every time we needed it, but we recently started running into rate-limit issues. So now we're caching it briefly, but figuring out how briefly is tricky, particularly given scenario #2 above. We want to avoid the rate limit, but not leave the window open too long. Knowing when the user signs out (without hitting a rate limit) would let us do that.