Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Authentication Issue #14

Closed
npateman opened this Issue · 2 comments

2 participants

@npateman

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;
    }
@soitgoes
Owner

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.

Thanks

Martin

@soitgoes
Owner

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 soitgoes closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.