How to get identity Teams user for joining a Teams meeting

Yossi Cahen 60 Reputation points
2024-03-29T09:14:05.89+00:00

Hello!

I use CallWithChatComposite to join a Teams meeting. One of the required props is "adapter" that require "userId" with a "CommunicationUserIdentifier" value:

export declare type AzureCommunicationCallWithChatAdapterArgs = {
    endpoint: string;
    userId: CommunicationUserIdentifier;
    displayName: string;
    credential: CommunicationTokenCredential;
    locator: CallAndChatLocator | TeamsMeetingLinkLocator;
    callAdapterOptions?: AzureCommunicationCallAdapterOptions;
};

export declare interface CommunicationUserIdentifier {
    /**
     * Id of the CommunicationUser as returned from the Communication Service.
     */
    communicationUserId: string;
}

For an external identity, I know to create a user access token and a userId as described here, but regarding a Teams identity I know to generate a user access token as described here, but which userId should I use? I try to use:

export const getUserId = async function () {
  const account = msalInstance.getActiveAccount();
  return account.localAccountId;
}

But it doesn't work.

I will appreciate you help

Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,120 questions
Azure Communication Services
Azure Communication Services
An Azure communication platform for deploying applications across devices and platforms.
684 questions
0 comments No comments
{count} votes

Accepted answer
  1. brtrach-MSFT 15,256 Reputation points Microsoft Employee
    2024-04-02T03:23:31.1133333+00:00

    @Yossi Cahen I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.

    Issue: You were unable to obtain the Team's user identity.

    Solution: You were able to use the below code to obtain the necessary Team's user identity.

    const communicationUserId = getIdentifierRawId({ "<TEAMS_USER_OBJECT_ID>" });
    
    

    If you have any other questions or are still running into more issues, please let me know. Thank you again for your time and patience throughout this issue.

    Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. brtrach-MSFT 15,256 Reputation points Microsoft Employee
    2024-03-30T00:21:58.6266667+00:00

    @Yossi Cahen To get the identity of a Teams user for joining a Teams meeting, you can use the getTokenForTeamsUser method of the CommunicationIdentityClient class to get a Communication Services access token for the Teams user.

    Here's an example of how to get the communicationUserId for a Teams user:

    const identityClient = new CommunicationIdentityClient("<COMMUNICATION_SERVICES_CONNECTION_STRING>");
    const teamsUserAadToken = "<TEAMS_USER_AAD_TOKEN>";
    const clientId = "<AAD_CLIENT_ID>";
    const userObjectId = "<TEAMS_USER_OBJECT_ID>";
    
    const accessToken = await identityClient.getTokenForTeamsUser({
        teamsUserAadToken: teamsUserAadToken,
        clientId: clientId,
        userObjectId: userObjectId,
    });
    
    const communicationUserId = { communicationUserId: accessToken.user.communicationUserId };
    

    You can then use the communicationUserId object as the userId parameter when creating the AzureCommunicationCallWithChatAdapterArgs object for the CallWithChatComposite component.

    0 comments No comments

  2. Yossi Cahen 60 Reputation points
    2024-04-01T11:11:10.1133333+00:00

    It doesn't work.

    That works for me:

    const communicationUserId = getIdentifierRawId({ "<TEAMS_USER_OBJECT_ID>" });
    
    0 comments No comments