I want to store the HTTP basic authentication headerline in an authentication cookie, so that I don't have to deal with the authorisation header in subsequent requests (I'm using JQuery):
authenticate: function(auth) {
var header = "Basic " + $.base64.encode(auth.username + ":" + auth.password);
document.cookie = "Authorization: " + header;
$.ajax({
type: "GET",
url: "http://someurl",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: auth.success,
error: auth.error
});
},
whilst this seems to work for the first user who logs in, it dosent work for any other users within the browser session, because the subsequent authorisation headers are added and not overwritten. I know that one could overwrite a cookie by using the name=value syntax, but this syntax does not apply to the authorization header.
Is there any way to get rid of the old authorization header, once a new user logs in?
Any help would be appreciated. Thanks, JeHo