Open atwoodr opened 4 years ago
Hi @atwoodr
Azure SignalR is not tested , let me some days to check this issue and I come back with more info! I try to solve the issue you mentioned with Azure SignalR and api key, bearer tokens, probably we need a new extension method for Azure SignalR
Sorry for the delay. I can confirm that Azure SignalR works as we already use it in several projects (.NET Core 2.2 and .NET Core 3.1). It works the same as SignalR. So, I suppose it is a configuration error.
@Odonno, what method does your Azure SignalR Health Check use to authenticate then? I've tried myriad ways of connecting to no avail. Or is your Azure SignalR somehow unsecured?
Well, it was a real nightmare for us because we use Azure AD authentication. We had to create an access token by reusing the Azure AD authority (the app is calling itself, with something like impersonation but without any real user authenticated). The only missing part is that you have to define this impersonation permission in the Azure AD configuration.
After that, it worked like a charm.
I assume that your problem is during configuration, what if you do this instead:
HubConnection CreateSignalrHubConnection(string url)
{
return new HubConnectionBuilder()
.WithUrl(url, options =>
{
options.AccessTokenProvider = async () =>
{
var credentials = await tokenManager.RetrieveCredentials(myAppAuthSettings);
return credentials.AccessToken;
};
})
.Build();
}
services.AddHealthChecks()
.AddSignalRHub(() => CreateSignalrHubConnection("https://myapp-signalr.service.signalr.net/notification"), "signalrTest2");
Note that you can cache the credentials of AccessTokenProvider
if you desire.
I've been trying to do what @Odonno suggested, but I'm getting a 404 error. Any idea how I can see more details of the error in health checks? This is what I have so far:
var con = "Endpoint=https://abc.service.signalr.net;AccessKey=keyhere;Version=1.0;";
this.serviceManager = new ServiceManagerBuilder()
.WithOptions(o => o.ConnectionString = con)
.Build();
hcBuilder.AddSignalRHub(() => CreateSignalrHubConnection(con), "signalr");
private HubConnection CreateSignalrHubConnection(string connString)
{
var url = $"{connString.Split(';')[0].Split('=')[1]}/notifications";
return new HubConnectionBuilder()
.WithUrl(url, options =>
{
options.AccessTokenProvider = () =>
Task.FromResult(this.serviceManager.GenerateClientAccessToken("notifications"));
})
.Build();
}
@unaizorrilla Will Azure SignalR be more supported in the near future? I'd like to be able to use the connection string that includes the key necessary to authenticate, I believe.
In case this helps anyone - instead of checking the Azure SignalR hubs (I am already checking the local ones in my app) I went with the standard health api on my endpoint using the connectionString:
services.AddHealthChecks()
.AddUrlGroup(
new Uri(
new Uri(new ServiceEndpoint(hubOptions.ConnectionString).Endpoint),
"/api/v1/health"),
name: "SignalR Azure Hub",
failureStatus: HealthStatus.Degraded,
tags: new[] { "cloud", "azure" });
@dviry This is a beautiful solution. Thanks.
Hi, I'm experiencing the same issue with Azure Signal R. I'm getting
Health check signalr with status Unhealthy completed after 669.4466ms with message '(null)' System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found).
I used the solution provided by @dviry hitting the Health API directly and it works. Please keep us posted if the issue is resolved for Azure Signal R.
What happened: We tried implementing SignalR health checks for our Azure SignalR resource(s), but no matter inputs we tried with the Xabaril
.AddSignalRHub(...)
method, we always got a 403 Forbidden response, an exception, and an unhealthy health check result.What you expected to happen: We expect the library to provide some way to verify a healthy Azure SignalR endpoint/hub/resource through either providing the Access Key or proper bearer token as part of the hub connection.
Things that do not appear to work:
Using a direct URL after attaching the signalR hub as an endpoint:
Using a direct URL after attaching the signalR hub as an endpoint:
AuthenticatedCredentials credentials = tokenManager.RetrieveCredentials(myAppAuthSettings) .GetAwaiter() .GetResult();
HubConnection connection = new HubConnectionBuilder() .WithUrl("https://myapp-signalr.service.signalr.net/notification", options => { options.AccessTokenProvider = () => Task.FromResult(credentials.AccessToken); }) .Build();
services.AddHealthChecks() .AddSignalRHub("https://myapp-signalr.service.signalr.net/notification", "signalrTest2");