Skip to content

Instantly share code, notes, and snippets.

@brianleroux
Forked from silentrob/htaccess_smart
Created March 18, 2010 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianleroux/336049 to your computer and use it in GitHub Desktop.
Save brianleroux/336049 to your computer and use it in GitHub Desktop.
system.use("info.webtoolkit.Base64");
var username = "admin";
var password = "password";
var auth = "Basic " + Base64.encode(username + ":"+ password);
checkAuth = function() {
if (!this.request.headers.hasOwnProperty('Authorization') || (this.request.headers.hasOwnProperty('Authorization') && (auth != this.request.headers['Authorization']))) {
this.response.headers['WWW-Authenticate'] = 'Basic realm="SmartAPI"';
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