question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] ChatThreadClient.AddParticipantAsync always returns forbidden

See original GitHub issue

Library name and version

Azure.Communication.Chat

Describe the bug

I’m trying to add a user to the chat thread whenever he enters an endpoint on my client application that triggers an api call that creates a record on a db saving his userid and token to be able to enters the room call and eventually the chat.

On client I’m using the UI library for ACS in React, but the problem triggers on backend. Backend: NET CORE 7 + Entity Framework

classeVirtualeEntity.ChatThreadId = the threadId saved on the entity on my database

IEnumerable<CommunicationTokenScope> scopes = new List<CommunicationTokenScope>
{
  new CommunicationTokenScope("voip"),
  new CommunicationTokenScope("chat")
};

Response<CommunicationUserIdentifierAndToken> tokenResponse = await _identityClient.CreateUserAndTokenAsync(scopes);

CommunicationTokenCredential chatTokenCredentials = new(tokenResponse.Value.AccessToken.Token);

ChatClient chatClient = new(new Uri("https://xxxxxxxx.communication.azure.com/"), chatTokenCredentials);

ChatThreadClient chatThreadClient = chatClient.GetChatThreadClient(classeVirtualeEntity.ChatThreadId);

await chatThreadClient.AddParticipantAsync(new ChatParticipant(tokenResponse.Value.User));

Expected behavior

await chatThreadClient.AddParticipantAsync(new ChatParticipant(tokenResponse.Value.User));

This line should add the partecipant and do no’t trigger an Exception.

Actual behavior

It won’t go further and triggers an Exception that I catch but it doesn’t specify anything else.

Reproduction Steps

I create the scopes

I create the ACS user id and token with the CommunicationIdentityClient service injected:

private readonly CommunicationIdentityClient _identityClient;

public MyService(CommunicationIdentityClient  identityClient){
  _identityClient = identityClient;
}

I create the CommunicationTokenCredential with the token from the user

I create the ChatClient with that and the endpoint of my ACS Service from Azure Portal

I retrieve the ChatThreadClient from ChatClient

I launch the method AddParticipantAsync

It triggers an Exception


Service request failed.
Status: 403 (Forbidden)

Content:
{
  "CommunicationError": {
    "Code": "Forbidden",
    "Message": "The initiator doesn't have the permission to perform the requested operation.",
    "Details": []
  }
}

Headers:
Transfer-Encoding: chunked
MS-CV: ySHzUBvxeUKgw7cNRLTRVg.0
Strict-Transport-Security: REDACTED
api-supported-versions: REDACTED
X-Processing-Time: REDACTED
x-ms-client-request-id: ac3aa147-80cf-466c-9a5f-5fef7f268da1
X-Cache: REDACTED
X-Azure-Ref: REDACTED
Date: Wed, 31 May 2023 12:46:06 GMT
Content-Type: application/json

Environment

No response

Issue Analytics

  • State:closed
  • Created 4 months ago
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
rdemacecommented, Jun 21, 2023

image

I think this is the parameter and it is valid.

0reactions
rdemacecommented, Jun 30, 2023

It worked, Thank you very much

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure Graph API : Error 403 Forbidden with Azure AD B2C
SendAsync(request); return response;. And I always obtain a 403 error Forbidden. The version of the assembly "Microsoft.IdentityModel.
Read more >
Troubleshoot Azure Digital Twins: Error 403 (Forbidden)
This article describes causes and resolution steps for receiving a 403 error from service requests to Azure Digital Twins.
Read more >
Custom Connector with Code enabled always returns
Hello everyone, I am trying to create a custom connector and to change the request's content with the avail of the "Code" functionality....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found