Works locally but not in production: Next-Auth ^5.0.0-beta.20 / Keycloak 18.0.2 / Next: ^14.2.2 #11648
Unanswered
FernandoBDAF
asked this question in
Help
Replies: 2 comments
-
pelo erro/log o problema nao esta no keycloak em si, mas pode estar na configuração de callback ou no deploy da aplicação dentro do next que responde por esse callback For an OAuth provider, possible causes are: The user denied access to the application |
Beta Was this translation helpful? Give feedback.
0 replies
-
use this solutions: #11684 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Provider type
Keycloak
Environment
System:
OS: macOS 14.6.1
CPU: (8) arm64 Apple M1
Memory: 62.23 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.16.0 - ~/.local/state/fnm_multishells/1832_1724242176301/bin/node
Yarn: 4.1.0 - ~/.local/state/fnm_multishells/1832_1724242176301/bin/yarn
npm: 10.8.1 - ~/.local/state/fnm_multishells/1832_1724242176301/bin/npm
Browsers:
Chrome: 127.0.6533.120
Safari: 17.6
Describe the issue
When running local, the Keycloak authentication works as expected. But when running on production, inside a docker environment managed by Kubernetes, We receive a 502 Bad Gateway response. The Next JS log says:
error { error: 'invalid_grant', error_description: 'Code not valid' }
[auth][error] CallbackRouteError: Read more at https://errors.authjs.dev#callbackrouteerror
[auth][cause]: Error: TODO: Handle OIDC response body error
at iE (/app/.next/server/chunks/7460.js:393:29404)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async iD (/app/.next/server/chunks/7460.js:393:35495)
at async iF (/app/.next/server/chunks/7460.js:393:46824)
at async iY (/app/.next/server/chunks/7460.js:393:51686)
at async /app/.next/server/chunks/8669.js:13:49805
at async /app/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:36258
at async eR.execute (/app/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:26874)
at async eR.handle (/app/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:37512)
at async doRender (/app/node_modules/next/dist/server/base-server.js:1377:42)
Questions:
Can you help me identify the cause of the issue?
Is it related to Keycloak misconfiguration?
Or it might be related to some difference in the production environment?
Why does the error mention a TODO?
How to reproduce
Next-Auth Version: ^5.0.0-beta.20
Keycloak Version: 18.0.2
Keycloak is configured with:
Client protocol: openid-connect
Access type: confidential
Client Authenticator: Client Id and Secret
The Valid Redirect URIs and Web Origins are also correctly set
Here's how I configured next-auth:
We also tested a simplified version. But this one did not kill the user's session upon sign-out.
We saw the same Bad Gateway error happening on production.
Here's the code:
Here's also how I configured a next-auth.d.ts:
Expected behavior
The user should be able to sign in with both google and/or facebook identity provider on production as it is doing locally.
Beta Was this translation helpful? Give feedback.
All reactions