我有一个自托管的服务堆栈应用程序,我正在使用Facebook Oath和Redis - Facebook和redis方面的东西似乎正在工作,即。当我访问时
abc.com/auth/facebook
自定义用户会话将在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>();
}
}
}
我如何注册缓存&amp;会议等。
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);
我觉得我在这里遗漏了一些明显的事情......提前感谢
答案 0 :(得分:0)
要注册使用CustomUserSession
作为您键入的会话,需要在注册AuthFeature时指定,例如:
Plugins.Add(new AuthFeature(() => new CustomUserSession(), ...));