mirror of
https://github.com/TiddlyWiki/TiddlyWiki5.git
synced 2026-04-24 20:44:35 +00:00
47 lines
1.2 KiB
JavaScript
47 lines
1.2 KiB
JavaScript
/*\
|
|
title: $:/core/modules/server/authenticators/header.js
|
|
type: application/javascript
|
|
module-type: authenticator
|
|
|
|
Authenticator for trusted header authentication
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
function HeaderAuthenticator(server) {
|
|
this.server = server;
|
|
this.header = server.get("authenticated-user-header");
|
|
}
|
|
|
|
/*
|
|
Returns true if the authenticator is active, false if it is inactive, or a string if there is an error
|
|
*/
|
|
HeaderAuthenticator.prototype.init = function() {
|
|
return !!this.header;
|
|
};
|
|
|
|
/*
|
|
Returns true if the request is authenticated and assigns the "authenticatedUsername" state variable.
|
|
Returns false if the request couldn't be authenticated having sent an appropriate response to the browser
|
|
*/
|
|
HeaderAuthenticator.prototype.authenticateRequest = function(request,response,state) {
|
|
// Otherwise, authenticate as the username in the specified header
|
|
var username = request.headers[this.header];
|
|
if(!username) {
|
|
response.writeHead(401,"Authorization header required to login to '" + state.server.servername + "'");
|
|
response.end();
|
|
return false;
|
|
} else {
|
|
state.authenticatedUsername = username;
|
|
return true;
|
|
}
|
|
};
|
|
|
|
exports.AuthenticatorClass = HeaderAuthenticator;
|
|
|
|
})();
|