Last post Nov 24, 2015 04:23 AM by SantyM
Nov 24, 2015 01:00 AM|SantyM|LINK
I have implemented Bearer token authentication in my signalr application. It is working fine except one problem, when authentication fails my application is unable to send custom message to client. SignalR always sends 400 - Unauthorized error when authentication
fails which is hard to capture at client side.
I want to send some custom JSON which client can parse and understand it is a bad token issue.
Nov 24, 2015 02:11 AM|Fei Han - MSFT|LINK
It is working fine except one problem, when authentication fails my application is unable to send custom message to client. SignalR always sends 400
It seems that you’d like to use the OAuth Bearer Token authentication with SignalR, this blog explained how to show different message to anonymous user and authenticated user, please refer to it.
Nov 24, 2015 04:23 AM|SantyM|LINK
Thanks for the reply. The solution provided above does not suit to my need. It is allowing the connection to client and then sends the message. Let me explain in detail. I have used AuthorizeAttribute and overritten UserAuthorized method which returns true
if user is authorized else false.
Public class myHub:Hub
// Hub methods goes here...
public bool UserAuthorized()
return true; // if authorized.
return false; // if not authorized.
My problem is SignalR is not allowing the connection if above method returns false. At client side in response to negotiate request it returns 400 Unathorized.
When above method returns true it response the proper negotiate response i.e. with all the expected fields connectiontoken,connectionid etc.