2015-05-11 10 views
5

Ho un'app di service stack autosospesa in cui sto utilizzando Facebook Oath e Redis: il lato Facebook e redis sembra funzionare, vale a dire. quando visitoAuthUserSession è nullo all'interno del servizio ServiceStack dopo l'autenticazione corretta

abc.com/auth/facebook 

La sessione utente personalizzata viene popolata nel metodo OnAuthenticated. La cache di Redis ha i dati persi correttamente .. così tanto bene

Il problema che sto avendo è capire come recuperare questa CustomUserSession in una richiesta successiva. Per iniziare con la pagina di reindirizzamento OAuth "/ Chi-Us" è dove voglio recuperare il valore di sessione tuttavia è sempre nullo

[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>(); 
     } 
    } 
} 

Come posso registrare la sessione di cache & ecc

 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); 

il contenuto di ConfigureAuth()

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

     Plugins.Add(authFeature); 

mi sento che mi manca qualcosa di ovvio qui .... grazie in anticipo

risposta

0

registrarsi per utilizzare un CustomUserSession per le sessioni digitati, deve essere specificato quando si registra l'AuthFeature, per esempio:

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

@MikeW E 'solo 'CustomId' che è nullo? In tal caso, dove lo stai compilando e dopo la sessione viene salvata? – mythz

+0

l'oggetto di sessione è new(), tutti i valori per la sessione sono presenti quando OnAuthenticate è chiamato come CustomId e Facebook Email ecc. In Redis Monitor posso vedere i dati della sessione SET con la chiave. Poi il reindirizzamento alla pagina del rasoio dove cerco di recuperare i valori - Posso collegare il codice del progetto se aiuta – MikeW

+0

@MikeW il 'SET' in Redis Monitor contiene il' CustomId'? Puoi anche vedere la richiesta di redazione 'GET' per accedere alla sessione personalizzata, sta usando la stessa chiave di sessione? – mythz

Problemi correlati