Commit 4ce9a91c authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

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=...
parent 1d583e53
...@@ -32,6 +32,9 @@ let groupStatus = {}; ...@@ -32,6 +32,9 @@ let groupStatus = {};
/** @type {string} */ /** @type {string} */
let username = null; let username = null;
/** @type {string} */
let token = null;
/** /**
* @typedef {Object} settings * @typedef {Object} settings
* @property {boolean} [localMute] * @property {boolean} [localMute]
...@@ -272,21 +275,29 @@ function setConnected(connected) { ...@@ -272,21 +275,29 @@ function setConnected(connected) {
/** @this {ServerConnection} */ /** @this {ServerConnection} */
async function gotConnected() { async function gotConnected() {
username = getInputElement('username').value.trim();
setConnected(true);
let pw = getInputElement('password').value;
getInputElement('password').value = '';
let credentials; let credentials;
if(!groupStatus.authServer) if(token) {
credentials = pw;
else
credentials = { credentials = {
type: 'authServer', type: 'token',
authServer: groupStatus.authServer, token: token,
location: location.href,
password: pw,
}; };
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 { try {
await this.join(group, username, credentials); await this.join(group, username, credentials);
...@@ -3740,6 +3751,7 @@ async function start() { ...@@ -3740,6 +3751,7 @@ async function start() {
group = decodeURIComponent( group = decodeURIComponent(
location.pathname.replace(/^\/[a-z]*\//, '').replace(/\/$/, '') location.pathname.replace(/^\/[a-z]*\//, '').replace(/\/$/, '')
); );
/** @type {Object} */ /** @type {Object} */
try { try {
let r = await fetch(".status.json") let r = await fetch(".status.json")
...@@ -3751,11 +3763,22 @@ async function start() { ...@@ -3751,11 +3763,22 @@ async function start() {
return; return;
} }
let parms = new URLSearchParams(window.location.search);
if(window.location.search)
window.history.replaceState(null, '', window.location.pathname);
setTitle(groupStatus.displayName || capitalise(group)); setTitle(groupStatus.displayName || capitalise(group));
addFilters(); addFilters();
setMediaChoices(false).then(e => reflectSettings()); 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(); setViewportHeight();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment