Skip to content

Commit

Permalink
Added very basic support for digest auth.
Browse files Browse the repository at this point in the history
  • Loading branch information
cskr committed Sep 9, 2010
1 parent 2f40c94 commit 8c82da1
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions grasshopper/lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,29 @@ RequestContext.prototype.getExtn = function() {
return extn;
};

RequestContext.prototype.getBasicAuth = function() {
var authHeader = this.request.headers.authorization;
if(authHeader && (authHeader.substring(0, 6) == "Basic ")) {
var authHeader = base64.decode(authHeader.substring(6));
var userPass = authHeader.split(":", 2);
return auth = {
RequestContext.prototype.getAuth = function() {
var authHeader = this.request.headers['authorization'];
if(authHeader && authHeader.substring(0, 6) == "Basic ") {
var credentials = base64.decode(authHeader.substring(6));
var userPass = credentials.split(":", 2);
return {
username: userPass[0],
password: userPass[1]
};
}
} else if(authHeader && authHeader.substring(0, 7) == "Digest ") {
var credentials = authHeader.substring(7);
var auth = {};
credentials.split(',').forEach(function(part) {
var subParts = part.trim().split('=');
var value = subParts[1];
if(value.charAt(0) == '"'
&& value.charAt(0) == value.charAt(value.length - 1)) {
value = value.substring(1, value.length - 1);
}
auth[subParts[0]] = value;
});
return auth;
}
};

RequestContext.prototype.addCookie = function(cookie) {
Expand Down

0 comments on commit 8c82da1

Please sign in to comment.