I am using next-auth in nextjs with keycloak as provider. The code snippet looks as follows:
const url = `http://localhost:8080/realms/<realm-name>/protocol/openid-connect/token`;
const keycloakParams = new URLSearchParams();
keycloakParams.append('client_id', process.env.KEYCLOAK_CLIENT_ID!);
keycloakParams.append('client_secret',process.env.KEYCLOAK_CLIENT_SECRET!);
keycloakParams.append('grant_type','refresh_token');
keycloakParams.append('refresh_token',<refreshToken>);
const TokenResponse = await axios.post(
url,
keycloakParams,
{
headers: { "Content-Type": "application/x-www-form-urlencoded" }
}
);
return response.json(TokenResponse.data);
This API call doesn't work, not sure what is the issue here.
I expected this API call to send the refresh tokens, and this works through postman. But this call is not working through javascript code