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