From 7d6f638b873aa6bab7e196a89f949d9af41996b1 Mon Sep 17 00:00:00 2001 From: Sam Frances Date: Fri, 5 May 2017 12:48:03 +0100 Subject: [PATCH] Add basic example auth plugin that checks the NoVNC token from the URL --- other/js/auth_plugin_examples.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 other/js/auth_plugin_examples.js diff --git a/other/js/auth_plugin_examples.js b/other/js/auth_plugin_examples.js new file mode 100644 index 0000000..8cce44c --- /dev/null +++ b/other/js/auth_plugin_examples.js @@ -0,0 +1,27 @@ +/* + * An auth plugin must be a function which returns a function conforing to the + * requirements of the `verifyClients` option on ws.WebSocket.Server. + * + * See: https://github.com/websockets/ws/blob/master/doc/ws.md + * + * If websockify is provided with an --auth-source argument, this will be + * passed to the auth plugin as its first argument. + * + */ + +const querystring = require('querystring'); + +exports.tokenAuth = function tokenAuth(source) { + return function(info) { + console.log(info.req.url); + let splitUrl = info.req.url.split("?") + if (splitUrl.length !== 2) { + return false; + } + let qs = splitUrl[1]; + let qs_parsed = querystring.parse(qs) + console.log(qs_parsed) + return (qs_parsed.token === source); + } +} +