成功验证后,AuthUserSession在ServiceStack服务中为空

Mik*_*keW 5 servicestack

我有一个自托管服务堆栈应用程序,我正在使用Facebook Oath和Redis - Facebook和redis方面的东西似乎正在工作,即.当我访问

abc.com/auth/facebook 
Run Code Online (Sandbox Code Playgroud)

自定义用户会话将在OnAuthenticated方法中填充.Redis缓存的数据保持正确.所以这么好

我遇到的问题是了解如何在后续请求中检索此CustomUserSession.从oauth重定向页面开始,"/ About-Us"是我想要检索会话值的地方,但它始终为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>();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我如何注册缓存和会话等

        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);
Run Code Online (Sandbox Code Playgroud)

ConfigureAuth()的内容

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

        Plugins.Add(authFeature);
Run Code Online (Sandbox Code Playgroud)

我觉得我在这里遗漏了一些明显的东西......先谢谢了

myt*_*thz 0

要注册为您键入的会话使用 a CustomUserSession,需要在注册 AuthFeature 时指定,例如:

Plugins.Add(new AuthFeature(() => new CustomUserSession(), ...));
Run Code Online (Sandbox Code Playgroud)