Client Authentication
Learn to authenticate clients in SignalR applications.
Authentications in SignalR
Only authenticated users can now access the hub. We now need to make sure that our clients can authenticate.
The JavaScript client
Because we are using cookie authentication, we don’t need to add anything extra to our JavaScript client. The back-end configuration ensures that the page is redirected to the login page if the user is not yet authenticated. Then the authentication cookie is being passed automatically in the request.
However, if we were to use our JavaScript client in a different context, we could get it to use the bearer token for authentication instead of a cookie. To do so, we would just need to add the following option to the withUrl
call on HubConnectionBuilder
:
Get hands-on with 1400+ tech skills courses.