I’m trying to establish a connection to Azure SignalR service from my Python backend but running into issues. My goal is to send messages through the SignalR connection.
Currently I’m attempting to use the CommunicationIdentityClient
library to obtain an access token, but when I execute the user creation method, I get a 403 forbidden error.
Here’s the code I’m working with:
from datetime import timedelta
from azure.communication.identity import CommunicationIdentityClient
connection_str = "Endpoint=https://myservice.service.signalr.net;AccessKey=mykey;Version=1.0;"
client_instance = CommunicationIdentityClient.from_connection_string(connection_str)
user_identity = client_instance.create_user()
print("\nUser created with ID: " + user_identity.properties['id'])
# Generate access token valid for 1 hour with voip scope
token_duration = timedelta(hours=1)
token_response = client_instance.get_token(user_identity, ["voip"], token_expires_in=token_duration)
print("\nGenerated token with 'voip' scope expires at " + token_response.expires_on + ":")
print(token_response.token)
I’m starting to suspect that CommunicationIdentityClient
might not be the correct library for SignalR connections. What’s the proper way to authenticate and connect to Azure SignalR from Python? Any guidance would be appreciated.