As per ServiceStack - Authentication for domain and subdomains, I set the cookie domain in the httpCookies section and it in fact works - it sets the domain of the cookie properly.
But what I noticed is, once I add this line to the config, a new session id is generated on every request, regardless if the user has already been authenticated.
My code is bare bones and simple.
My app host code:
public override void Configure(Funq.Container container)
{
Plugins.Add(new AuthFeature(() => new CustomUserSession(),
new IAuthProvider[] {
new CustomCredentialsProvider(),
}));
container.Register<IRedisClientsManager>(c => new PooledRedisClientManager("10.211.55.2:6379"));
container.Register<ICacheClient>(c => c.Resolve<IRedisClientsManager>().GetCacheClient());
var userRep = new InMemoryAuthRepository();
container.Register<IUserAuthRepository>(userRep);
}
My custom credentials provider:
public class CustomCredentialsProvider : CredentialsAuthProvider
{
public override bool TryAuthenticate(ServiceStack.IServiceBase authService, string userName, string password)
{
return true;
}
public override void OnAuthenticated(ServiceStack.IServiceBase authService, IAuthSession session, IAuthTokens tokens, Dictionary<string, string> authInfo)
{
session.UserAuthName = "test user";
session.UserName = "test user";
authService.SaveSession(session);
}
}
My default page:
public partial class _Default : WebForms.App_Start.PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
//get session information in every way possible
var session = this.UserSession;
var sessionKey = SessionFeature.GetSessionKey();
var session2 = SessionFeature.GetOrCreateSession<CustomUserSession>(this.Cache);
var session3 = this.Cache.Get<CustomUserSession>(sessionKey);
}
sessionKey, above, will be issued and will stay the same on every request (which is expected). Adding:
<system.web>
<httpCookies domain="localhost"/>
causes sessionKey to be different every request; almost like the cookie is immediately expiring. Changing the domain to something like 'test.com' or '.test.com' doesn't seem to make a difference. I added 127.0.0.1 localhost and 127.0.0.1 test.com to my windows hosts file for good measure.
Again, commenting out the httpCookies line and the session id stays the same, even after authenticating. Adding the above line causes session to change on every request, regardless of authenticating or not.
Cookies are being set, and they are set with the new session id on every request.
What might I be doing wrong and where would I override this behavior? Any help is appreciated.