AuthUserSession is null inside ServiceStack after successful authorization

I have a stand-alone hosting application in which I use Facebook Oath and Redis - Facebook and redis side of things seem to work, i.e. when i visit

abc.com/auth/facebook 

The user's user session is logged into the OnAuthenticated method. The Redis cache stores data correctly .. so good

Problem Im has an understanding of how to get this CustomUserSession in a subsequent request. To start the oauth redirect page, "/ About-Us" is where I want to get the session value, but always null

 [DataContract] public class CustomUserSession : AuthUserSession { [DataMember] public string CustomId { get; set; } public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IAuthTokens tokens, Dictionary<string, string> authInfo) { // receiving session id here and can retrieve from redis cache } public override bool IsAuthorized(string provider) { // when using the [Authenticate] attribute - this Id is always // a fresh value and so doesn't exist in cache and cannot be auth'd string sessionKey = SessionFeature.GetSessionKey(this.Id); cacheClient = ServiceStackHost.Instance.TryResolve<ICacheClient>(); CustomUserSession session = cacheClient.Get<CustomUserSession>(sessionKey); if (session == null) { return false; } return session.IsAuthenticated; } } [DefaultView("AboutUs")] public class AboutUsService : AppServiceBase { public object Get(AboutUsRequest request) { var sess = base.UserSession; return new AboutUsResponse { //custom Id is always null?? Name = sess.CustomId }; } } public abstract class AppServiceBase : Service { protected CustomUserSession UserSession { get { return base.SessionAs<CustomUserSession>(); } } } 

How do I register cache and session, etc.

  AppConfig = new AppConfig(appSettings); container.Register(AppConfig); container.Register<IRedisClientsManager>(c => new PooledRedisClientManager("10.1.1.10:6379")); container.Register(c => c.Resolve<IRedisClientsManager>().GetCacheClient()); ConfigureAuth(container, appSettings); 

ConfigureAuth () content

  var authFeature = new AuthFeature( () => new CustomUserSession(), new IAuthProvider[] { new FacebookAuthProvider(appSettings), // override of BasicAuthProvider } ) {HtmlRedirect = null, IncludeAssignRoleServices = false}; Plugins.Add(authFeature); 

I feel like I'm missing something obvious here ... thanks in advance

+5
source share
1 answer

To register the use of CustomUserSession for the entered sessions, it must be specified when registering AuthFeature, for example:

 Plugins.Add(new AuthFeature(() => new CustomUserSession(), ...)); 
0
source

All Articles