POST API request fails with "Didn't find publicKey for specified kid"

Hi,

I have logged into a WEB API application with admin user and got a valid JWT token. The user is configured in WebAPIAdmins realm.

The GET API call https://localhost:8000/management/store/info?id=1ca75046-fa02-4a4d-8a0e-a96a41309686 works well with the token

But the POST API request https://localhost:8000/management/store/update?id=1ca75046-fa02-4a4d-8a0e-a96a41309686, fails with the following message

Bearer realm=WebAPICustomers", error=“invalid_token”, error_description=“Didn’t find publicKey for specified kid”

The Bearer realm got in the error message is different from the one to which the user belongs.

What could be the reason?
How can I solve the issue?

The system has three realms, given below. The realm is selected based on uri path at run time.

    1. WebAPICustomers
    2. WebAPIAdmins
    3. WebAPISellers

In the issue scenario WebAPIAdmins realm is selected by the keycloak config class.

WebAPIConfigResolver implements KeycloakConfigResolver
{

 public KeycloakDeployment resolve(HttpFacade.Request request)
{

    if (request.getRelativePath().startsWith(MANAGEMENT_PATH)) {
        return managementKeycloakDeployment;
    }
}

}