From 4143b0008a342376ff1cac7ab824993c9fe830a7 Mon Sep 17 00:00:00 2001 From: Sam Frances Date: Fri, 5 May 2017 14:14:31 +0100 Subject: [PATCH] Add example auth plugin that reads password from a file --- other/js/auth_plugin_examples.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/other/js/auth_plugin_examples.js b/other/js/auth_plugin_examples.js index 769a25a..241df9b 100644 --- a/other/js/auth_plugin_examples.js +++ b/other/js/auth_plugin_examples.js @@ -10,6 +10,7 @@ */ const querystring = require('querystring'); +fs = require('fs'); function urlTokenMatch(url, token, verbose=false) { let splitUrl = url.split("?") @@ -42,3 +43,18 @@ exports.tokenAuthEnv = function tokenAuthEnv(source) { return urlTokenMatch(info.req.url, token, true); } } + +exports.tokenAuthFile = function tokenEnvFile(source) { + return function(info, cb) { + fs.readFile(source, 'utf8', function(err, data) { + if (err) { + console.log(err); + cb(false); + } else { + let token = data.trim(); + let success = urlTokenMatch(info.req.url, token, true); + cb(success); + } + }); + } +} \ No newline at end of file