Application(Client) Sample code (HTML)
<html>
<head>
<title>SSO Test</title>
<script src="https://openidserver.redirectme.net:8443/auth/js/keycloak.js"></script>
<script>
var keycloak = Keycloak('OpenID.json');
function reloadData(){
keycloak.updateToken(10)
.success(frmLogin_getOpenIDCallback)
.error(function() {
alert('Failed to load data. User is logged out');
});
}
function LoginSSO()
{
keycloak.init({ onLoad: 'login-required' })
.success(reloadData)
.error(function(errorData) {
document.getElementById('customers').innerHTML = '<b>Failed to load data. Error: ' + JSON.stringify(errorData) + '</b>';
alert(JSON.stringify(errorData));
});
}
function frmLogin_getOpenIDCallback()
{
console.log(keycloak);
console.log(keycloak.token);
}
if (window.location.hash != "")
{
LoginSSO();
}
</script>
</head>
<body>
<br><br>
<button onclick="LoginSSO()">SSO login</button>
</body>
</html>