Skip to content

Instantly share code, notes, and snippets.

@kusor
Created December 28, 2009 11:45
Show Gist options
  • Save kusor/264642 to your computer and use it in GitHub Desktop.
Save kusor/264642 to your computer and use it in GitHub Desktop.
Smart HTTP Basic Auth
before(function(){
system.use("info.webtoolkit.Base64");
var username = 'foo';
var password = 'bar';
var auth = "Basic " + Base64.encode(username + ":"+ password);
if (!this.request.headers.hasOwnProperty('Authorization') || (this.request.headers.hasOwnProperty('Authorization') && (auth != this.request.headers['Authorization']))) {
this.response.headers['WWW-Authenticate'] = 'Basic realm="Protected Area"';
this.response.code = 401;
this.response.body = "Not Authorized\n";
throw this.response;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment