handle extension for auth

This commit is contained in:
AJ ONeal 2018-06-06 10:56:38 +00:00
parent 73f26d6e05
commit 224c3ac9cd
2 changed files with 27 additions and 10 deletions

View File

@ -130,20 +130,30 @@ function applyConfig(config) {
, debug: state.config.debug || state.config.greenlock.debug
});
try {
// TODO specify extensions in config file
state.extensions = require('../lib/extensions');
} catch(e) {
if (state.debug) { console.log('[DEBUG] no extensions loaded', e); }
state.extensions = {};
}
require('../lib/handlers').create(state); // adds directly to config for now...
//require('cluster-store').create().then(function (store) {
//program.store = store;
state.authenticate = function (opts) {
try {
state.extensions = require('./extensions');
return state.extensions.authenticate({
state: state
, auth: opts.auth
});
} catch(e) {
// ignore
if (state.extensions.authenticate) {
try {
return state.extensions.authenticate({
state: state
, auth: opts.auth
});
} catch(e) {
console.error('Extension Error:');
console.error(e);
}
}
return state.defaults.authenticate(opts.auth);
};

View File

@ -116,9 +116,16 @@ module.exports.create = function (state) {
//
var serveAdmin = require('serve-static')(__dirname + '/../admin', { redirect: true });
var finalhandler = require('finalhandler');
state.httpTunnelServer = http.createServer(function (req, res) {
res.setHeader('connection', 'close');
state.defaults.webadmin = function (req, res) {
serveAdmin(req, res, finalhandler(req, res));
};
state.httpTunnelServer = http.createServer(function (req, res) {
//res.setHeader('connection', 'close');
if (state.extensions.webadmin) {
state.extensions.webadmin(state, req, res);
} else {
state.defaults.webadmin(req, res);
}
});
Object.keys(state.tlsOptions).forEach(function (key) {
tunnelAdminTlsOpts[key] = state.tlsOptions[key];