I am trying to implement PKCE flow with keycloak and reactJS. I am generating code_challange and code verifier in my react client application.
I have adapter configuration as follows :
{
"realm": "demo",
"auth-server-url": "http://localhost:8080/auth/",
"issuer": "http://localhost:8080/auth/realms/demo",
"scope": "openid profile email offline_access",
"code-challenge-method": "S256",
"ssl-required": "external",
"resource": "javascript-app",
"verify-token-audience": true,
"use-resource-role-mappings": true,
"confidential-port": 0,
"enable-pkce": true,
"public-client": true,
"pkce-method": "S256",
"response-type": "code"
}
I am generating the auth URL as follows :
// _kc is keycloak client adapter instance
function generateUrl() {
const { code_verifier, code_challenge } = pkceChallenge();
const URL = _kc.createLoginUrl();
const CODE_CHALLENGE = "&code_challenge=" + code_challenge;
const CODE_CHALLENGE_METHOD = "&code_challenge_method=S256";
const CODE_VERIFIER = "code_verifier" + code_verifier;
return URL + CODE_CHALLENGE + CODE_VERIFIER + CODE_CHALLENGE_METHOD;
window.open(authorizationUrl, "_self");
}
So far everything works fine. But when it is redirect to the app from keycloak auth page the subsequent post request to get access token is failing with the following error : url : http://localhost:8080/auth/realms/demo/protocol/openid-connect/token
{error: "invalid_grant", error_description: "PKCE code verifier not specified"}
It is clear that the code_verifier is not being passed with the form data. Due to this client keycloak instance is failing to initiate after redirecting.
How to fix this issue by updating the token access request in keycloak to pass code_verifier and code along with the form data ?