I have a react application that using keycloak for some protected routes. I am creating a new keycloak instance with the following json :
{
"realm": "demo",
"auth-server-url": "http://localhost:8080/auth/",
"ssl-required": "external",
"resource": "javascript-app",
"public-client": true,
"verify-token-audience": true,
"use-resource-role-mappings": true,
"confidential-port": 0
}
The init method is defined as follows to enable PKCE :
export function initKeycloak() {
_kc.init({
onLoad: "check-sso",
pkceMethod: "S256",
silentCheckSsoRedirectUri:
window.location.origin + "/silent-check-sso.html",
});
}
The problem is when the keycloak instance created it is not authenticating automatically in scenarios like refreshing the page. Thoese requests are returning with error message like :
http://localhost:3000/keycloak/login#error=invalid_request&error_description=Missing+parameter%3A+code_challenge_method&state=4ebff627-22af-4d25-864a-9e90ccd089f7
I tried adding the following in the json file:
"on-load": "check-sso",
"code-challenge-method": "S256",
"pkce-method": "S256",
But they are not working.
Is there a way to eliminate this error while keycloak instance is created ? or to invoke keycloak.init() automatically before keyclaok turns to initialized state ?