AuthUserSession is null inside ServiceStack service after successful auth -
i have self hosted service stack app in i'm using facebook oath , redis - facebook , redis side of things seem working ie. when visit
abc.com/auth/facebook
the custom user session gets populated in onauthenticated method. redis cache has data persisted correctly..so far good
the problem im having understanding how retrieve customusersession in subsequent request. begin oauth redirect page "/about-us" want retrieve session value 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 , can retrieve redis cache } public override bool isauthorized(string provider) { // when using [authenticate] attribute - id // fresh value , doesn't exist in cache , cannot 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 null?? name = sess.customid }; } } public abstract class appservicebase : service { protected customusersession usersession { { return base.sessionas<customusersession>(); } } }
how register cache & 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);
the contents of configureauth()
var authfeature = new authfeature( () => new customusersession(), new iauthprovider[] { new facebookauthprovider(appsettings), // override of basicauthprovider } ) {htmlredirect = null, includeassignroleservices = false}; plugins.add(authfeature);
i feel i'm missing obvious here.... in advance
to register use customusersession
typed sessions, needs specified when register authfeature, e.g:
plugins.add(new authfeature(() => new customusersession(), ...));
Comments
Post a Comment