From b9779715f82a322ef8354dc5bcfafcd9d31fafd5 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 5 Jun 2018 02:21:12 -0600 Subject: [PATCH] send auth info --- lib/remote.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/remote.js b/lib/remote.js index 3da3845..3769984 100644 --- a/lib/remote.js +++ b/lib/remote.js @@ -12,9 +12,10 @@ function timeoutPromise(duration) { }); } -function run(state) { +function _connect(state) { // jshint latedef:false - var activityTimeout = state.activityTimeout || (2*60 - 5)*1000; + var defaultHttpTimeout = (2 * 60); + var activityTimeout = state.activityTimeout || (defaultHttpTimeout - 5) * 1000; var pongTimeout = state.pongTimeout || 10*1000; // Allow the tunnel client to be created with no token. This will prevent the connection from // being established initialy and allows the caller to use `.append` for the first token so @@ -477,19 +478,24 @@ function run(state) { }; function connect() { - if (!tokens.length) { - console.warn("[Non-fatal Error] No tokens. Nothing to do."); - return; - } + var auth; if (wstunneler) { console.warn('attempted to connect with connection already active'); return; } + if (tokens.length) { + auth = 'access_token=' + tokens[0]; + } else if (state.config.email) { + auth = 'subject=' + state.config.email; + auth += '&subject_scheme=mailto'; + // TODO create domains list earlier + auth += '&scope=' + Object.keys(state.config.servernames || {}).join(','); + } timeoutId = null; var machine = Packer.create(packerHandlers); console.info("[connect] '" + state.relay + "'"); - var tunnelUrl = state.relay.replace(/\/$/, '') + '/?access_token=' + tokens[0]; + var tunnelUrl = state.relay.replace(/\/$/, '') + '/?' + auth; wstunneler = new WebSocket(tunnelUrl, { rejectUnauthorized: !state.insecure }); wstunneler.on('open', wsHandlers.onOpen); wstunneler.on('close', wsHandlers.onClose); @@ -601,7 +607,7 @@ function run(state) { }; } -module.exports.connect = run; -module.exports.createConnection = run; +module.exports.connect = _connect; +module.exports.createConnection = _connect; }());