Skip to content

Instantly share code, notes, and snippets.

@georgehemmings
Last active February 8, 2016 09:53
Show Gist options
  • Save georgehemmings/8d57e7b39df30e268415 to your computer and use it in GitHub Desktop.
Save georgehemmings/8d57e7b39df30e268415 to your computer and use it in GitHub Desktop.
public override void Configure(Container container)
{
container.RegisterAs<OneSessionAuthEvents, IAuthEvents>();
}
using System.Collections.Generic;
using System.Linq;
using ServiceStack;
using ServiceStack.Auth;
using ServiceStack.Caching;
using ServiceStack.Web;
namespace Orca.ServiceInterface.Authentication
{
public class OneSessionAuthEvents : AuthEvents
{
public override void OnAuthenticated(IRequest httpReq,
IAuthSession session,
IServiceBase authService,
IAuthTokens tokens,
Dictionary<string, string> authInfo)
{
using (var cache = authService.TryResolve<ICacheClient>())
{
var sessionPattern = IdUtils.CreateUrn<IAuthSession>("");
var sessionKeys = cache.GetKeysStartingWith(sessionPattern).ToList();
var allSessions = cache.GetAll<IAuthSession>(sessionKeys);
var existingSessions = allSessions.Where(s => s.Value.UserName == session.UserName);
cache.RemoveAll(existingSessions.Select(s => s.Key));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment