Forge External Auth Provider (Keycloak): hasCredentials() returns false after successful authentication

Issue Summary:
We are experiencing an issue with Forge’s External Auth Provider integration using Keycloak. After a successful authentication, `keycloak.hasCredentials()` incorrectly returns `false` on the first attempt, but returns `true` on subsequent requests.

Environment:

  • Forge App using External Auth Provider
  • Auth Provider: Keycloak
  • Runtime: Node.js 20.x
  • Forge API: @Forge/api

Code Implementation:
const keycloak = await api.asUser().withProvider(“keycloak”, “custom-backend”);
if (!(await keycloak.hasCredentials([“email”]))) {
await keycloak.requestCredentials();
}