How to get current user's tenant id rather than application's tenant id in MS Teams tab app (React JS)

Viewed 33

I am building a MS Teams Tab app using React JS, https://docs.microsoft.com/en-us/microsoftteams/platform/tabs/what-are-tabs. For each app, we need to create an App Registration in Azure console. Now, in my application I am trying to retrieve the logged in user's tenant ID rather than app tenant ID.

First thing I know is that I can get the tenant ID from SSO token. So I tried to retrieve the SSO token as follow using @microsoft/teams-js package.

initialize();

    const authOptions: authentication.AuthTokenRequest = {
      successCallback:(token) => {
           // when I decode the token, the tid field is still  giving me app registration tenant's id (user can be guest and can belong to different tenant)
       },
      failureCallback:(error) => {

     },
    };

    authentication.getAuthToken(authOptions);

Please pay attention to the comment in the code above.

I can get the user's tenant ID if I force the user to login using MSAL with this libraries, @azure/msal-react and @azure/msal-browser. The access token gives me the tid of the user. But the thing is that I do not want to force the user to login. How can I get the user's tennant ID without forcing the user to login?

0 Answers
Related