Search code examples
azureazure-active-directorymicrosoft-teamsaccess-tokenazure-communication-services

Can not create and use token to use ACS for a teams user: "CallAgent must be created only with ACS token."


I am trying to follow two tutorials, both are working, still my use case gives an error.

  • first is how to get ACS token for a Teams user here (for the C# code jump directly within the tutorial here) (NOTE: My real use case is a web app, so I got the token slightly different way, but the token itself exactly the same content and issue)
  • second how to create a custom web application which uses @azure/communication-common @azure/communication-react packages to participate in a teams call. here (See point 11.where I place my token in case you want the details)

The first seems to be working, I am logging with my [email protected], and got the token: (the guid 53b----b70 is my user id in the tenant))

{
  "skypeid": "orgid:53b*****-****-****-****-*********b70",
  "scp": 1024,
  "csi": "1715345005",
  "exp": 1715349008,
  "rgn": "emea",
  "tid": "937*****-****-****-****-*********7d1",
  "acsScope": "voip,chat",
  "resourceId": "871*****-****-****-****-*********86d",
  "aad_iat": "1715345005",
  "aad_uti": "E4*****************oAA",
  "aad_appid": "1fd5118e-2576-4263-8130-9503064c837a",// ACS Service Principal
  "iat": 1715345305
}

The second is also working, if I am using the generated (unverified user) Identity and Access Token values from my configured Communication Service page on the Azure portal.

Issue:

If I try to use the application in the second tutorial to join to the meeting as Teams user ([email protected]), and try to use the Identity 53b----b70, and the successfully generated token from the first tutoial above, I got the error message:

CallError: CallClient.createCallAgent: CallAgent must be created only with ACS token

The error message hints that my portal generated token below which is has a "skypeid" which begins with acs: but the not working my Teams user token's skypeid starts with orgid:? But how can get such a token for my Teams user?

// portal generated token which is working, skypid starts with acs, 
// and in form of acs:{resourceId}_{randomuser-id}. 
// According to portal generated Identitiy which is the same with 8: prefix
{
  "skypeid": "acs:871*****-****-****-****-*********86d_000*****-****-****-****-*********fc1", 
  "scp": 1792,
  "csi": "1715344681",
  "exp": 1715431081,
  "rgn": "emea",
  "acsScope": "chat,voip",
  "resourceId": "871*****-****-****-****-*********86d",
  "resourceLocation": "europe",
  "iat": 1715344681
}

Solution

  • According to this changelog, you have to use TeamsCallAgent instead of CallAgent.

    const userToken = '<ACCESS_TOKEN_FOR_MICROSOFT_365_IDENTITY>';
    callClient = new CallClient();
    const tokenCredential = new AzureCommunicationTokenCredential(userToken);
    const teamsCallAgent = await callClient.createTeamsCallAgent(tokenCredential);