I’ve been fighting this off and on for weeks.
I’m trying to follow this: Securing Applications and Services Guide
I’m running Keycloak 19.0.1 on OpenJDK 18.
I have this simple HTML lifted from the documentation. It’s being served by the simple python server: python3 -m http.server 8000
<!DOCTYPE html>
<html>
<head>
<script src="keycloak.js"></script>
<script>
function initKeycloak() {
const keycloak = new Keycloak();
keycloak.init({
onLoad: 'login-required'
}).then(function (authenticated) {
alert(authenticated ? 'authenticated' : 'not authenticated');
}).catch(function () {
alert('failed to initialize');
});
}
</script>
<title>Keycloak Test</title>
</head>
<body onload="initKeycloak()">
Hello World
</body>
</html>
I got the keycloak.js file from: wget http://localhost:8080/js/keycloak.js
This is my keycloak.json
{
"realm": "test-realm",
"auth-server-url": "http://localhost:8080/",
"ssl-required": "external",
"resource": "test-client",
"credentials": {
"secret": "really_really_sekrit"
},
"confidential-port": 0
}
I got this from the test-client page in the admin console, from the Admin drop down → Download Adapter Config. This is in contrast to what the document says, which appears out of date. The secret is elided, but I understand that the secret should not be necessary, but I include it for completeness.
I see access to index.html, keycloak.js, and keycloak.json.
When I visit the page, it redirects me to the keycloak login page. I enter the user credential, it accepts the credential, then back on my page and I get the alert “failed to initialize”. In the keycloak log, it says:
2022-11-14 10:38:33,509 WARN [org.keycloak.events] (executor-thread-32) type=CODE_TO_TOKEN_ERROR, realmId=68683e28-08b1-45c2-b58f-82ea0f0af868, clientId=test-client, userId=null, ipAddress=127.0.0.1, error=invalid_client_credentials, grant_type=authorization_code
But the username and password are correct.
I’ve tried several different tutorials, they fail in different ways, so I’m just back here at square one, trying to get a Hello World going. Trying to make any progress. Right now, my progress is Edison-esque “I know dozens of things that don’t work”.
Any insight appreciated.