soitgoes/LoveSeat — Issue #14: Authentication Issue
Author: firkinfedup
Created: 2011-10-12 14:44:44+00:00
State: open

Hi there,

I'm not entirely sure if this is down to the way we have our server setup or not, but in order to get cookie authentication to work I had to modify the CouchBase GetSession method, even after reading the documentation I'm still confused as to why I had to add this, but it seems to work great now...

(I added the line to include the Authorization header to the web request, it seems to require that and also the form data)

public Cookie GetSession()
{
var authCookie = cookiestore["authcookie"];

if (authCookie != null)
return authCookie;

if (string.IsNullOrEmpty(username)) return null;
var request = new CouchRequest(baseUri + "_session");
request.GetRequest().Headers.Add("Authorization:Basic " + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password)));
var response = request.Post()
.Form()
.Data("name=" + username + "&password=" + password)
.GetResponse();

var header = response.Headers.Get("Set-Cookie");
if (header != null)
{
var parts = header.Split(';')[0].Split('=');
authCookie = new Cookie(parts[0], parts[1]);
authCookie.Domain = response.Server;
cookiestore.Add("authcookie", authCookie, TimeSpan.FromMinutes(9));
}
return authCookie;
}