Authenticating SignalR Hubs in a Blazor Server app

I’m trying to secure a SignalR hub in an Blazor Server app and can’t find any end to end examples of this.

I have configured the app in the startup with AddAuth0WebAppAuthentication and WithAccessToken.

A token is being picked up in the request to the SignalR hub from the component that builds the Hub connection and I’m setting the AccessTokenProvider with that access token from Auth0

Whenever the Hub connection tries to connect to the apps hubs, it throws a 401 Unauthorized.

The hubs work correctly when I remove the authorise attribute from them. Have tried this using the ASP.NET JWT setup too, but still get the same error.

Normal authorisation works fine

Hey Statto1974, were you ever able to figure out a solution for this? I am running into the exact same situation. When I remove the [Authorize] header from the hub, it will work, however it is in an unauthorized state in the hub so I have no ability to see the currently logged in user or their claims.

Your post is the only one (after days of googling around and asking chat gpt) that is identical to what I’m facing.