KEYCLOAK-15158 adjust basic example of Keycloak JS adapter usage
As the JS adapter has evolved, it now tries to add an iframe element to the document body during initialization. When used like in the basic example as before, there will be an JS error, as the document body is not yet available. So we've to wait until the document is loaded, thus the initialization is put in a function and the function will be called upon body.onload()
This commit is contained in:
parent
8ff235e630
commit
f9e5d78a56
1 changed files with 13 additions and 6 deletions
|
@ -24,17 +24,24 @@ The following example shows how to initialize the JavaScript adapter:
|
||||||
|
|
||||||
[source,html]
|
[source,html]
|
||||||
----
|
----
|
||||||
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<script src="keycloak.js"></script>
|
<script src="keycloak.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
function initKeycloak() {
|
||||||
var keycloak = new Keycloak();
|
var keycloak = new Keycloak();
|
||||||
keycloak.init().then(function(authenticated) {
|
keycloak.init().then(function(authenticated) {
|
||||||
alert(authenticated ? 'authenticated' : 'not authenticated');
|
alert(authenticated ? 'authenticated' : 'not authenticated');
|
||||||
}).catch(function() {
|
}).catch(function() {
|
||||||
alert('failed to initialize');
|
alert('failed to initialize');
|
||||||
});
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
<body onload="initKeycloak()">
|
||||||
|
<!-- your page content goes here -->
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
----
|
----
|
||||||
|
|
||||||
If the `keycloak.json` file is in a different location you can specify it:
|
If the `keycloak.json` file is in a different location you can specify it:
|
||||||
|
|
Loading…
Reference in a new issue