0

i am currently developing a real time analytic Dashboard with Stream Analytics -> Azure Functions -> SignalRService -> Angular Web App. I am struggling when i want to authorize my function with the signalr service. Therefore i added the Connectionstring to my Appsettings. When i try to send a SignalRMessage, it says that i am unauthroized. Isnt it just setting the Connectionstring with the Accesskey in AppSettings of the Function?

Current Error:

Microsoft.Azure.SignalR.Common.AzureSignalRUnauthorizedException: 'Authorization failed. If you were using AccessKey, please check connection string and see if the AccessKey is correct. If you were using Azure Active Directory, please note that the role assignments will take up to 30 minutes to take effect if it was added recently. Request Uri: https://signalrtest2.service.signalr.net/api/v1/hubs/pa'

FunctionCode:

[FunctionName("CreateRealTimeAnalytics")]
    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
        [SignalR(HubName = "pa")] IAsyncCollector<SignalRMessage> signalRMessages)
    {
        // Extract the body from the request
        string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
        if (string.IsNullOrEmpty(requestBody)) { return new StatusCodeResult(204); } // 204, ASA connectivity check

        var data = JsonConvert.DeserializeObject<StreamUsageHeartbeatAnalytics>(requestBody);
        var dataString = Newtonsoft.Json.JsonConvert.SerializeObject(data);
        await signalRMessages.AddAsync(
            new SignalRMessage
            {
                Target = "pa",
                Arguments = new[] { dataString }
            });

        return new OkResult(); // 200
    }

    [FunctionName("Negotiate")]
    public static SignalRConnectionInfo Negotiate(
        [HttpTrigger(AuthorizationLevel.Anonymous)] HttpRequest req,
        [SignalRConnectionInfo(HubName = "pa")] SignalRConnectionInfo connectionInfo)
    {
        return connectionInfo;
    }
sINFflwies
  • 69
  • 2
  • 6

1 Answers1

0

To achieve the above requirement we have tried to add the below connection string format which is working fine So please make sure that you have provided proper Connection string with below format in your Appsettings.

Azure__SignalR__ConnectionString : Value(My connection string)

enter image description here

For more information please refer the below Links:-

AjayKumarGhose
  • 4,257
  • 2
  • 4
  • 15