WebPubSub client can't join a group but can join other groups of the same access_token
We successfully create access_token for PubSub which includes webpubsub.joinLeaveGroup and webpubsub.sendToGroup for 4 groups (like A, B, C and D, so 8 roles in total) but the client (which is MAUI app) can't join the group D and receives "Received non-success acknowledge from the service: The client does not have permission to join group 'D'."!
I can confirm that once access_token is generated, we re-initialize the WebPubSubClient with the new token (which is successful) and then:
- We are able to send message to group A
- We are able to join group C
But we can't join group D!
Below is a last section of Python API code that generates the access_token. 'groups' variable is sent like 'A|B|C|D':
....
all_roles = []
for group_name in groups.split('|'):
all_roles.append("webpubsub.joinLeaveGroup." + group_name)
all_roles.append("webpubsub.sendToGroup." + group_name)
wsClient = WebPubSubServiceClient.from_connection_string(connectionstring, hub)
token_key = wsClient.get_client_access_token(roles=all_roles, minutes_to_expire=1440)
return str(token_key['url'])
In MAUI, our initialize and join group methods are:
public async Task InitializeConnection(string pubSubUrl)
{
try
{
_client = new WebPubSubClient(new Uri(pubSubUrl));
_client.GroupMessageReceived += HandleMessage;
await _client.StartAsync();
_isConnected = true;
}
catch (Exception ex)
{
_isConnected = false;
throw new Exception($"Failed to initialize WebSocket connection: {ex.Message}");
}
}
public async Task JoinGroup(string groupName)
{
if (!_isConnected)
throw new InvalidOperationException("WebSocket is not connected");
try
{
await _client.JoinGroupAsync(groupName);
}
catch (Exception ex)
{
throw new Exception($"Failed to join group {groupName}: {ex.Message}");
}
}