Authentication Issue #14

npateman opened this Issue Oct 12, 2011 · 2 comments


None yet
2 participants

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()
            .Data("name=" + username + "&password=" + password)

        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;

soitgoes commented Oct 13, 2011

Thanks for the contributions. It will be helpful if you can fork and send me pull request for these rather than just providing the comment.

Let me know if there is anything I can do to help.




soitgoes commented Dec 13, 2011

Fixed in 7bf7c1.

Sorry about the delay. I can get to these much quicker if you can send me pull request in the future. Thanks for your contribution though.

soitgoes closed this Dec 13, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment