`oauth2/token` endpoint returns 502 Bad Gateway error
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:
This is the error response that I am getting:
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!3 Replies
Hi @samwell ,
You're encountering a 502 Bad Gateway error when making a POST request to the /oauth2/token endpoint with the following payload:
{ "client_id": "YOUR_CLIENT_ID", "client_secret": "YOUR_CLIENT_SECRET", "grant_type": "authorization_code", "redirect_uri": "YOUR_REDIRECT_URI", "code": "AUTHORIZATION_CODE" }This suggests the server acting as a gateway received an invalid response from the upstream server. This can happen if the request parameters are sent as query parameters instead of in the POST body. Ensure all parameters are included in the body and the Content-Type header is set to application/x-www-form-urlencoded. Example Fix:
const response = await fetch(- Ensure KINDE_SUBDOMAIN includes the full URL (e.g., https://your-subdomain.kinde.com). - Verify connectivity to the Kinde endpoint using tools like curl or Postman. - Check server logs and intermediary proxies for additional error details. - Refer to Kinde's documentation for further guidance: https://docs.kinde.com/developer-tools/about/using-kinde-without-an-sdk Implement these changes, and let us know if you encounter further issues${KINDE_SUBDOMAIN}/oauth2/token
, { method: "POST", body: new URLSearchParams({ client_id: KINDE_CLIENT_ID, client_secret: KINDE_CLIENT_SECRET, grant_type: "authorization_code", redirect_uri: KINDE_REDIRECT_URL, code: authCode, }), headers: { "Content-Type": "application/x-www-form-urlencoded" }, }); if (response.ok) { const data = await response.json(); // Process data } else { console.error(Error: ${response.status} ${response.statusText}
); }
Kinde docs
Using Kinde without an SDK
Our developer tools provide everything you need to get started with Kinde.
That seems to have worked! Thank you very much!
Hi @samwell ,
I'm glad to hear that the solution worked and resolved your issue. We'll go ahead and close this ticket. If you have any more questions in the future, feel free to open a new one.