Permalink
Browse files

Fixed issue #14. Authorization header not passed on session request.

  • Loading branch information...
1 parent 94c277e commit 7bf7c1734b82e9911354abd7e7183e0fda250eeb @soitgoes committed Dec 13, 2011
Showing with 4 additions and 13 deletions.
  1. +4 −13 LoveSeat/Support/CouchBase.cs
@@ -33,38 +33,29 @@ public static bool Authenticate(string baseUri, string userName, string password
.GetResponse();
return response.StatusCode == HttpStatusCode.OK;
}
-
- protected Cookie GetSession()
- {
+ 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()
- .ContentType("application/x-www-form-urlencoded")
+ .Form()
.Data("name=" + username + "&password=" + password)
.GetResponse();
- // add check
- if (response == null)
- {
- throw new NullReferenceException("Response from authentication post yielded a null reference exception.");
- }
-
var header = response.Headers.Get("Set-Cookie");
- if (header != null)
- {
+ 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;
}
-
protected CouchRequest GetRequest(string uri)
{
return GetRequest(uri, null);

0 comments on commit 7bf7c17

Please sign in to comment.