-
Notifications
You must be signed in to change notification settings - Fork 448
Authorize attribute doesn't work with SignalR ASP.Net Core 2.1 #1764
Comments
You need to put it on the Hub itself, not the OnConnectedAsync method. |
Thank you. I think this issue can be closed. |
Hi, @davidfowl I've configured an authorization flow for my Asp.Net core app and use the [Authorize] attribute for the SignalR hub:
OnConnectedAsync method works fine, I can see all user claims according to an access_token, but when I've decided to check network I have found the following error in console:
Another problem, OnDisconnectedAsync method will never be called, even if I closed the browser tab. The token is provided from the client angular app:
And the access_token looks like:
Not sure but maybe it is because in the GET request contains token without schema "Bearer": |
This is expected. Browsers don't allow us to encode the |
@anurse I've investigated more and define, that WebSockets and ServerSentEvents transports are failed to start because of this: I didn't use method AddJwtBearer in startup class, authentication is configured by the following code: I've tried to add AddJwtBearer to the services but after all my API queries return 500 error, suppose because of the different validation schema |
@anurse Solved this problem by the following code:
Actually the same as described in the documentation you have referenced. Thank you for help. Close the issue! |
Yeah, |
One important note: It is very strongly recommended that you only use the query string when the request is for your SignalR endpoint. Notice that the docs have code to check based on the path before reading from the query string. Your sample code reads from the I recommend you restrict this based on path and/or only do it if the request is a WebSocket (which you can check easily by checking that the |
@anurse sure, it is just a base implementation. I'll provide check hub path logic. Thank you a lot! |
Hi,
I've follow getting started with SignalR ASP.NET Core 2.1. My application worked fine until I put
[Authorize]
attribute to my hub.I created one Authentication requirement:
In my
Startup.cs
, I added these code blocks:In my hub, I put my
Authorize
attribute like this:What I expected was
SolidRequirementHandler
would be called, but it jumped straight intoOnConnectedAsync
method ofChatHub.cs
.Am I doing anything wrong ?
Thank you,
The text was updated successfully, but these errors were encountered: