Last post Aug 04, 2015 11:05 AM by Dan Kellett
Jul 31, 2015 02:31 PM|Dan Kellett|LINK
I am attempting to set the context user within a custom Authorize attribute using the pattern below.
public class CustomAuthorizeAttribute : AuthorizeAttribute
public override bool AuthorizeHubConnection(HubDescriptor hubDescriptor, IRequest request)
// authenticate by using bearer token in query string
var token = GetToken();
if (token != null)
var user = GetUserFromDb(token);
var principal = new CustomPrincipal(user.ID, user.LoginId);
request.GetHttpContext().User = principal;
//request.Environment["server.User"] = principal;
However, when I attempt to retrieve the custom principal user within the Hub like the following code, the cast returns null.
public override Task OnConnected()
var customPrincipal = Context.User as CustomPrincipal;
Is there another way to achieve this?
The following thread details a method that now does not work.
Aug 03, 2015 04:01 AM|Krunal Parekh|LINK
I think you might need to create your own identity class for this.
Please see this similar thread:
Hope this helps.
Aug 04, 2015 11:05 AM|Dan Kellett|LINK
Thanks, I did start sown that track, however I want to do this in katana middleware not in the webforms /mvc pipleline.
This is running within a webforms app, but it is using a very custom authentication pattern. I do have access to a bearer token which I can validate. I want this validation to happen in katana startup as middleware, not in the signalr plumbing. I think this
makes a lot of sense to put this inside the map for signalR, but it seems that any time a "use" or "run" is added within the signalr mapping it breaks.
This now probably warrants another thread of discussion.