SignalR - OnConnect () authorization - how to disable an unauthorized user?

In my hub, I have something like this (pseudocode):

public override Task OnConnected() { var isLegal = Authorize(); if (!isLegal) //not authorized { //how do I deny him this connection? } return base.OnConnected(); } 

How to disconnect / prohibit connection to the user?

+6
source share
2 answers

Add the authorize attribute above the class, the user will be denied if it is not authenticated.

+1
source

The following link explains how to authenticate and authorize the hub.

http://www.asp.net/signalr/overview/security

If you decide not to use the existing auth mechanism, you will need to check whether the user is allowed in each method of the hub and return the appropriate messages.

0
source

Source: https://habr.com/ru/post/954521/


All Articles