For frontend react, I am using ReactKeycloakProvider as a way to require user to login, then token should be stored into Keycloak from 'keycloak-js'.
<ReactKeycloakProvider
authClient={MYKEYCLOAK}
initOptions={{onLoad: 'login-required'}}
>
<BrowserRouter>
<MainRouter />
</BrowserRouter>
</ReactKeycloakProvider>
For Keycloak, I am using Keycloak v.20.0.2, the client access type is set to confidential as it is required, Client Authenticator is Client Id and Secret.
The problem is that, after user login, I cannot get the token, an error 401 occurs:
{
"error":"unauthorized_client",
"error_description":"Invalid client or Invalid client credentials"
}
. However, I am expecting to get the token successfully.
I have set the access type into public, then token is retrieved successfully. However, when I set it into confidential, 401 error will occurs. So I think it is because I have not put client secret into the keycloak object.
Also, tried to have a keycloak.json for putting client secret into keycloak config, like this:
import Keycloak from 'keycloak-js';
const KEYCLOAK = new Keycloak('/keycloak.json');
But it can only be recognize when the .json is placed in public folder, which is weird, and infinite loop will occurs.