Welcome to the Kinde community

Home
Members
samwell
s
samwell
Offline, last seen 3 days ago
Joined January 14, 2025
I am trying to call the /oauth2/token endpoint from a Hono.js server (running in a Bun environment) and am getting a 502 Bad Gateway response. This is my code:

Plain Text
import { Hono, type Context } from "hono";
import { GrantType } from "@kinde-oss/kinde-typescript-sdk";

const api = new Hono();

api.get("/my-route-path", async (c: Context) => {
  const url = new URL(c.req.url);
  const authCode = url.searchParams.get("code");
  const response = await fetch(`${KINDE_SUBDOMAIN}/oauth2/token`, {
    method: "POST",
    body: JSON.stringify({ 
      client_id: KINDE_CLIENT_ID,
      client_secret: KINDE_CLIENT_SECRET,
      grant_type: GrantType.AUTHORIZATION_CODE,
      redirect_uri: KINDE_REDIRECT_URL,
      code: authCode,
    }),
    headers: { "Content-Type": "application/json" },
  });
});

This is the error response that I am getting:
sh
{
ok: false,
url: "https://my-kinde-subdomain/oauth2/token",
status: 502,
statusText: "Bad Gateway",
headers: Headers {
"date": "Tue, 14 Jan 2025 02:03:49 GMT",
"content-type": "text/html",
"content-length": "122",
"connection": "keep-alive",
"server": "awselb/2.0",
},
redirected: false,
bodyUsed: false,
Blob (122 bytes)
}
```

I am following the docs on this page: https://docs.kinde.com/developer-tools/about/using-kinde-without-an-sdk/

Has anyone run into this? Thank you!