From 4ce9a91c40398cd623dfc385e0c92701f217fecc Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Fri, 18 Feb 2022 20:27:53 +0100 Subject: [PATCH] Implement passing tokens in URL search parameters. It is now possible to autojoin by going to a URL such as https://galene.example.org/group/test?username=jch&token=... --- static/galene.js | 49 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/static/galene.js b/static/galene.js index ff18ef4..2a25b32 100644 --- a/static/galene.js +++ b/static/galene.js @@ -32,6 +32,9 @@ let groupStatus = {}; /** @type {string} */ let username = null; +/** @type {string} */ +let token = null; + /** * @typedef {Object} settings * @property {boolean} [localMute] @@ -272,21 +275,29 @@ function setConnected(connected) { /** @this {ServerConnection} */ async function gotConnected() { - username = getInputElement('username').value.trim(); - setConnected(true); - - let pw = getInputElement('password').value; - getInputElement('password').value = ''; let credentials; - if(!groupStatus.authServer) - credentials = pw; - else + if(token) { credentials = { - type: 'authServer', - authServer: groupStatus.authServer, - location: location.href, - password: pw, + type: 'token', + token: token, }; + token = null; + } else { + username = getInputElement('username').value.trim(); + setConnected(true); + + let pw = getInputElement('password').value; + getInputElement('password').value = ''; + if(!groupStatus.authServer) + credentials = pw; + else + credentials = { + type: 'authServer', + authServer: groupStatus.authServer, + location: location.href, + password: pw, + }; + } try { await this.join(group, username, credentials); @@ -3740,6 +3751,7 @@ async function start() { group = decodeURIComponent( location.pathname.replace(/^\/[a-z]*\//, '').replace(/\/$/, '') ); + /** @type {Object} */ try { let r = await fetch(".status.json") @@ -3751,11 +3763,22 @@ async function start() { return; } + let parms = new URLSearchParams(window.location.search); + if(window.location.search) + window.history.replaceState(null, '', window.location.pathname); setTitle(groupStatus.displayName || capitalise(group)); + addFilters(); setMediaChoices(false).then(e => reflectSettings()); - document.getElementById("login-container").classList.remove('invisible'); + if(parms.has('token')) { + username = parms.get('username'); + token = parms.get('token'); + await serverConnect(); + } else { + let container = document.getElementById("login-container"); + container.classList.remove('invisible'); + } setViewportHeight(); }