Created
December 28, 2009 11:45
-
-
Save kusor/264642 to your computer and use it in GitHub Desktop.
Smart HTTP Basic Auth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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