gpt4 book ai didi

servicestack - 身份验证成功后,ServiceStack 服务中的 AuthUserSession 为空

转载 作者:行者123 更新时间:2023-12-03 17:43:32 24 4
gpt4 key购买 nike

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

abc.com/auth/facebook 

自定义用户 session 填充在 OnAuthenticated 方法中。 Redis 缓存已正确保存数据......到目前为止一切顺利

我遇到的问题是了解如何在后续请求中检索此 CustomUserSession。从 oauth 重定向页面开始,“/About-Us”是我想要检索 session 值的地方,但它始终为空
[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>();
}
}
}

我如何注册缓存和 session 等。
        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() 的内容
        var authFeature = new AuthFeature(
() => new CustomUserSession(),
new IAuthProvider[]
{
new FacebookAuthProvider(appSettings), // override of BasicAuthProvider
}
) {HtmlRedirect = null, IncludeAssignRoleServices = false};

Plugins.Add(authFeature);

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

最佳答案

注册使用 CustomUserSession对于键入的 session ,需要在注册 AuthFeature 时指定,例如:

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

关于servicestack - 身份验证成功后,ServiceStack 服务中的 AuthUserSession 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30176884/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com