Skip to main content

Keycloak 客户端

Javascript Adapter

npm add keycloak-js
<head>
<script src="keycloak.js"></script>
<script>
var keycloak = new Keycloak();
keycloak
.init()
.then(function (authenticated) {
alert(authenticated ? 'authenticated' : 'not authenticated');
})
.catch(function () {
alert('failed to initialize');
});
</script>
</head>
new Keycloak('http://localhost:8080/myapp/keycloak.json');
new Keycloak({
url: 'http://keycloak-server/auth',
realm: 'myrealm',
clientId: 'myapp',
});

keycloak.init({
onLoad: 'check-sso',
// onLoad: 'login-required'
silentCheckSsoRedirectUri: window.location.origin + '/silent-check-sso.html',
});

silent-check-sso.html

<html>
<body>
<script>
parent.postMessage(location.href, location.origin);
</script>
</body>
</html>

keycloak-config-cli