Is it possible to use ServiceStack auth with a SignalR hub?


If we were to use SignalR alongside ServiceStack instead of SSE, would it be possible to authenticate using ServiceStack auth and also access the ServiceStack session within the SignalR hub?

If so, how would I go about doing this please?

Thank you.

You can host SignalR and ServiceStack together (excluding self host) but session and authentication isn’t shared. You can broadcast messages from standard ServiceStack services to SignalR hubs but this has hosting limitations as well and listeners wouldn’t be limited to ServiceStack authenticated users.

If SignalR lets you access Request Cookies you may be able to retrieve the authenticated user with something like:

var sessionId = Context.Request.Cookies[SessionFeature.SessionId]; //ss-id
if (sessionId != null)
    var sessionKey = SessionFeature.GetSessionKey(sessionId.Value);
    var cache = HostContext.AppHost.GetCacheClient();
    var session = cache.Get<IAuthSession>(sessionKey);
    if (session.IsAuthenticated)

If user were authenticated with RememberMe=true then the session would be stored against their permanent Session Id, i.e. SessionFeature.PermanentSessionId (ss-pid).