extremum-cli
Version:
Extremum CLI
57 lines (53 loc) • 1.73 kB
HTML
<html>
<head>
<script src="js/keycloak.js" type="text/javascript"></script>
<script type="text/javascript">
async function initKeycloak() {
let errorTimeout;
function showMessage(message) {
document.getElementById('message').textContent = message;
if (errorTimeout !== undefined) {
clearTimeout(errorTimeout);
}
}
errorTimeout = setTimeout(
() => showMessage('Cannot connect to the authentication service. Make sure the URL you specified is correct'),
1000
);
const response = await fetch('/config');
const data = await response.json();
const keycloak = Keycloak(data.config);
const loadData = () => {
console.log(keycloak.subject);
if (keycloak.token) { // was .idToken
console.log('Token:', keycloak.token);
fetch('/token', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({token: keycloak.token})
}).then(() => showMessage('Now you may close this page'));
}
};
const loadFailure = () => {
showMessage('Failed to load data. Check browser console');
};
const reloadData = () => {
keycloak.updateToken(300)
.then(loadData)
.catch(() => {
showMessage('Failed to load data. Check browser console');
});
}
keycloak.init({onLoad: 'login-required', checkLoginIframe: false}).then(reloadData).catch(e => {
showMessage('Login failed');
console.error(e);
});
}
</script>
</head>
<body onload="initKeycloak()">
<h1 id="message"></h1>
</body>
</html>