oidc: enable auto login when a token is provided
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user