Stephen Brannan - 288 - Mar 28, 2014

Can you suggest a way to check user auth in SignalR? Several posts refer to the SessionFeature.GetOrCreateSession<AuthUserSession> method but this requires a ServiceStack request which I don’t have within SignalR (SignalR has it’s own request).

It’s a matter of reading the ss-id cookie from the HTTP request and retrieving the session from the cache, here’s the code that does it in SS:
https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack/SessionExtensions.cs#L177

the ss cookies calls GetSessionKey to create the cache key:
https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack/SessionFeature.cs#L80 

Essentially something like:

var sessionId = GetCookieFromSignalR(“ss-id”);
var sessionKey = IdUtils.CreateUrn<IAuthSession>(sessionId);
var userSession = cache.Get<MyUserSession>(sessionKey);

If  authentication is made with “RememberMe=true” then you want to read the “ss-pid” cookie instead, this preference is stored in the ss-opt cookie.

Stephen Brannan:

Thank you so much +Demis Bellot This is exactly what I was looking for!