-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PKCE code_verifier cookie was missing.. on keycloak OIDC login #11641
Comments
I patched the Here's the full sequence of logs I gathered leading up to the error: correct idp hint
correct keycloak URL
correct provider
seems to create the PKCE code verifier correctly
pkce has a vale in
pkce cookie exists in
in the code challenge, the value matches one of the previous pkce values
authorization url is ready with pkce cookie
signIn url seems correct
callbackUrl is the 3rd party oidc login website, which seems right.
@auth/core internalRequest.url
in @auth/core oauth checks file, the pkce cookies is empty 😞, this is the cause of the error, but the problem is that it shouldn't be empty.
resCookies are also empty
cookie options
the pkce codeVerifier is
|
Interestingly, and possibly another bug? If I try the same login in incognito I get a different error:
I'm not writing or calling any actions myself besides the |
Today I attempted to downgrade to Downgrading to New behavior:
@balazsorban44 Any idea why this happens? |
@MarkLyck in the browser, do you see the cookies being set successfully before the redirection to Keycloak? (Using |
@ThangHuuVu Thank you for the response! And sorry the reply is a bit late, we can only deploy on Tuesdays and Thursdays to test this. Here are the browser cookies that get set for me with next-auth@beta (v5) This screenshot is taken from the |
@ThangHuuVu @balazsorban44 Hmmm I believe we might have figured out the reason for this. For the affected clients, we have an HTTP proxy that opens a new HTTP connection to Vercel but still preserving the URL hostname so Vercel knows who it is. This is required due to their custom SSL certificates. So when next-auth used the VERCEL domain name ENV variable, it's actually using the wrong domain name for the authentication. Sadly we cannot use the Is there any way to dynamically set the auth URL? It would be easy if we could just set it in the config. But I didn't see this in the docs. I'm going to attempt dynamically setting the |
@ThangHuuVu @balazsorban44 The above attempt failed. I tried both setting the But the user is still getting redirected back to the Vercel domain after it authenticates with Keycloak 😞 |
Found a thread with a similar looking issue: #10928 I tried implementing the suggest workaround, and that does make next-auth redirect to the correct URL. But the URLs used in the internal requests within next-auth, including
So while the URLs are not correct in the browser, the PKCE code verifier cookie missing error still remains. @ThangHuuVu @balazsorban44 any other ideas we can try to get this working with next-auth? I'm pretty sure the issue is that next-auth uses the wrong URL based on the Vercel environment variable, but I don't see any way to dynamically override this for multi tenancy sites. |
I managed to do something similar:
To get the auth redirect working, I removed
And then as part of the configuration:
This appears to work just fine when using The key difference from what i understood the documentation to infer was that all deployments need the I understand this is not exactly your use case but i do hope it helps. |
@jack828 Thanks for the comment Jack. We did try using the We're still stuck on this. I've pretty much given up trying to get next-auth working, and attempting to get it working with the cc @ThangHuuVu @balazsorban44 Would still really love some input here if you have time 😞 if only it was possible to override the URL next-auth uses in the config or provider config, I believe it would work. |
@MarkLyck If you come up with an app router solution using keycloak-js, I'd appreciate a gist or something !! I'm also stuck on this. |
@dclark27 We're still struggling with this as well. Likewise, if you find a solution please post it. 🙏 We did a test with keycloak-js today, but that also failed, and redirected the user to the keycloak login screen when they should already be authenticated via OIDC. |
I've been working on this for a few weeks as well, if anybody has made any progress with either next-auth or keycloak-js, I would love to learn more about it. |
Environment
Reproduction URL
https://github.com/MarkLyck/keycloak-pkce-error-reproduction
Describe the issue
I have been stuck on this error for 2 weeks, and could really use some help.
I'm using next-auth@5.0.0-beta.18, with multiple Keycloak providers.
The "main" keycloak provider with direct login works fine both on localhost, and when the app is deployed on Vercel. However we also have two keycloak providers with OIDC logins, which only exists in production. When I deploy my app to production, and attempt to login from these two different sites through Keycloak I get the error:
Before this error happens, it looks like the PKCECODEVERIFIER is created succesfully:
After the users attempts to login the above error happens and they are redirected to /api/auth/error?error=Configuration
With a message that says: "There is a problem with the server configuration. Check the server logs for more information".
auth config;
signIn function with idp_hint:
How to reproduce
I created a minimal reproduction, but it requires setting up a 3rd party OIDC system to reproduce the issue, so it's no small task. 😞
eas
as the idp_hintI'm replacing a client-side keycloak system with next-auth. Everything besides adding next-auth is the exact same, and my 3rd party OIDC login through keycloak works fine in current production, but broken when I deploy next-auth
Expected behavior
User should be logged in and redirect to
/
The text was updated successfully, but these errors were encountered: