问题
In our 365 add-in, we're using the Office.context.mailbox.userProfile.emailAddress API to get the user's email address, for authentication/data retrieval with our own backend (e.g. get the user's data). It returns inconsistent results depending on the user's 365 setup. Some users who have SSO setup with their org will have a completely different email returned from that API after they go through the OAuth process - meaning that it will return something like jon.smith@domain.com pre-OAuth, then after OAuth is complete, that same value will return j.smith@global.domain.com, or some permutation of that scenario. Other users will have that API return one email when they're on OWA, and a different email when they're on the desktop clients.
Since our backend uses email address as the unique ID, this causes some problems for us. I'm wondering if there is a better way to handle getting the user's email address, or identity in general. I remember reading about a 365 API that was not production ready to deal with SSO sign-ins, but that was a while ago, maybe its production ready now? I've been unable to find any additional information about that feature.
If anybody can shed any light on whats going on with the scenarios I described above I'd appreciate it.
edit - this is the SSO sign in feature that isn't production ready I was talking about https://docs.microsoft.com/en-us/office/dev/add-ins/develop/sso-in-office-add-ins
the date looks like it was updated really recently, so is it safe to assume that it isn't going to be production ready for a while?
回答1:
For an identifier, instead of email address, you can get an uniqueId from UserIdentityToken using API getUserIdentityTokenAsync https://docs.microsoft.com/en-gb/office/dev/add-ins/reference/objectmodel/requirement-set-1.5/Office.context.mailbox#getuseridentitytokenasynccallback-usercontext
We do acknowledge that there are conditions that we might return different addresses on userProfile.emailAddress and this issue has been put in our backlog.
(this is already discussed in previous comments, just posting as answer for clarity)
来源:https://stackoverflow.com/questions/55521840/users-mailbox-api-returning-different-emails-when-on-owa-vs-desktop-client-or