oidc: enable auto login when a token is provided

This commit is contained in:
Johannes Zellner
2024-04-03 18:11:21 +02:00
parent 91d3980e3b
commit 2f6a66dbd7
2 changed files with 54 additions and 4 deletions

View File

@@ -105,10 +105,9 @@ document.getElementById('loginForm').addEventListener('submit', function (event)
document.getElementById('internalError').classList.add('hide');
document.getElementById('busyIndicator').classList.remove('hide');
var apiUrl = '<%= submitUrl %>';
console.log('submit', apiUrl);
const apiUrl = '<%= submitUrl %>';
var body = {
const body = {
username: document.getElementById('inputUsername').value,
password: document.getElementById('inputPassword').value,
totpToken: document.getElementById('inputTotpToken').value
@@ -150,6 +149,30 @@ document.getElementById('loginForm').addEventListener('submit', function (event)
});
});
const token = location.search.slice(1);
if (token) {
console.log('got token do auto login', token);
const apiUrl = '<%= submitUrl %>';
let res;
fetch(apiUrl, {
method: 'POST',
body: JSON.stringify({ token: token }),
headers: { 'Content-type': 'application/json; charset=UTF-8' }
}).then(function (response) {
res = response;
return res.json(); // we always return objects
}).then(function (data) {
if (data.redirectTo) window.location.href = data.redirectTo;
else console.log('login success but missing redirectTo in data:', data);
}).catch(function (error) {
document.getElementById('internalError').classList.remove('hide');
document.getElementById('busyIndicator').classList.add('hide');
console.warn(error, res);
});
}
</script>
</body>