Skip to content
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

[BUG] Redirect loop when keycloak auth is enabled #604

Closed
4 tasks done
kafeinnet opened this issue Apr 19, 2022 · 13 comments
Closed
4 tasks done

[BUG] Redirect loop when keycloak auth is enabled #604

kafeinnet opened this issue Apr 19, 2022 · 13 comments
Assignees
Labels
🐛 Bug [ISSUE] Ticket describing something that isn't working 🕸️ Inactive

Comments

@kafeinnet
Copy link

Environment

Self-Hosted (Docker)

Version

2.0.7

Describe the problem

Hi,

Dashy cause a redirect loop when keycloak auth is enable and I'm not sure how I can debug that.

The app keeps redirecting to my keycloak server (/auth/realms/myrealm/protocol/openid-connect/auth?client_id=... and all the auth workflow).
Then keycloak redirect to the app callback https://fqdn/#state=....
Then there is a POST request on /auth/realms/myrealm/protocol/openid-connect/token and keycloak returns a JSON objet which seems to be a valid bearer token.
And then the app refresh itself and everything starts again.

The keycloak session is OK, the returned token is OK, some other apps are using this keycloak instance without problem and dashy is working OK if I don't enable keycloak auth. Is there any way to be sure this a a dashy bug or to find out what is happening ?

\fab

Additional info

No response

Please tick the boxes

@kafeinnet kafeinnet added the 🐛 Bug [ISSUE] Ticket describing something that isn't working label Apr 19, 2022
@liss-bot

This comment was marked as outdated.

@kafeinnet
Copy link
Author

Oh, I haven't starred the repo, my bad.
And I can confirm I check all the documentations, logs, sections and opened issues.

@Lissy93 Lissy93 reopened this Apr 19, 2022
@Lissy93
Copy link
Owner

Lissy93 commented Apr 19, 2022

No worries, I've reopened it :)

Do you know what version of Keycloak you're running?

If it's an older version (before v17.0.0), then this will be the same as #564.
Basically Keycloak changed their API endpoint, and I updated the code accordingly in fd2b3d8, but this then dropped support for older versions of Keycloak. I will soon put a fix out (adding an option in appConfig.auth.keycloak for legacy support).


Otherwise, this issue is covered in Troubleshooting Docs --> Keycloak Redirect Error, I've pasted below

Fixing Keycloak Redirect Error

Check the browser's console output, if you've not set any headers, you will likely see a CORS error here, which would be the source of the issue.

You need to allow Dashy to make requests to Keycloak, and Keycloak to redirect to Dashy. The way you do this depends on how you're hosting these applications / which proxy you are using, and examples can be found in the Management Docs.

For example, add the access control header to Keycloak, like:

Access-Control-Allow-Origin [URL-of Dashy]

Note that for requests that transport sensitive info like credentials, setting the accept header to a wildcard (*) is not allowed - see MDN Docs, so you will need to specify the actual URL.

You should also ensure that Keycloak is correctly configured, with a user, realm and application, and be sure that you have set a valid redirect URL in Keycloak (screenshot).

For more details on how to set headers, see the Example Headers in the management docs, or reference the documentation for your proxy.


Similar questions have been raised before, and the users shared their solutions, so see also:

@kafeinnet
Copy link
Author

I use keycloak 15 !

I upgrade it to the latest on my dev environment as soon as I can. I have to do it anyway.

@liss-bot liss-bot added the 👤 Awaiting Maintainer Response [ISSUE] Response from repo author is pending label Apr 19, 2022
@kafeinnet
Copy link
Author

I just upgraded keycloak from v15 to v17. This new version breaks most of my other apps because the URI does not start with /auth anymore. So, I guess that's what #564 is about.

But, unfortunately, there is still the same redirect loop.

Here is a screenshot of my browser's console (up to date firefox).

2022-04-19_17-23

The home.something domain is dashy and auth.something is keycloak.

@liss-bot liss-bot removed the 👤 Awaiting Maintainer Response [ISSUE] Response from repo author is pending label Apr 19, 2022
@kafeinnet
Copy link
Author

kafeinnet commented Apr 19, 2022

I double checked the CORS headers, they seem fine.

image

Maybe I am missing something obvious...

BTW, I can see the returned token. So I doubt that's a CORS problem here.

@liss-bot liss-bot added 👤 Awaiting Maintainer Response [ISSUE] Response from repo author is pending and removed 👤 Awaiting Maintainer Response [ISSUE] Response from repo author is pending labels Apr 19, 2022
@liss-bot
Copy link
Collaborator

This issue has gone 6 weeks without an update. To keep the ticket open, please indicate that it is still relevant in a comment below. Otherwise it will be closed in 5 working days.

@liss-bot liss-bot added the ⚰️ Stale [ISSUE] [PR] No activity for over 1 month label May 21, 2022
@PlusaN
Copy link

PlusaN commented May 25, 2022

@Lissy93 @kafeinnet Hi!

Fixing Keycloak Redirect Error

For example, add the access control header to Keycloak, like:
Access-Control-Allow-Origin [URL-of Dashy]

This is a bad way for Keycloak, don't use this method! If we add such headers, we will get endless redirect loop.
To solve the problem with CORS headers, you need to fill in the "Web Origins" field in the Keycloak settings:
image

"Web Origins" tooltip: Allowed CORS origins. To permit all origins of Valid Redirect URIs, add '+'. This does not include the '*' wildcard though. To permit all origins, explicitly add '*'.

It's working for me (without adding headers on NGINX server). Keycloak 18.0.0

@liss-bot liss-bot added 👤 Awaiting Maintainer Response [ISSUE] Response from repo author is pending and removed ⚰️ Stale [ISSUE] [PR] No activity for over 1 month labels May 25, 2022
@xcojonny
Copy link

Worked for me too. Using keycloak 16 and Træfik. Thanks 😊 @PlusaN

@liss-bot liss-bot removed the 👤 Awaiting Maintainer Response [ISSUE] Response from repo author is pending label May 28, 2022
@liss-bot
Copy link
Collaborator

This issue has gone 6 weeks without an update. To keep the ticket open, please indicate that it is still relevant in a comment below. Otherwise it will be closed in 5 working days.

@liss-bot liss-bot added the ⚰️ Stale [ISSUE] [PR] No activity for over 1 month label Jun 27, 2022
@liss-bot
Copy link
Collaborator

liss-bot commented Jul 2, 2022

This issue was automatically closed because it has been stalled for over 6 weeks with no activity.

@liss-bot liss-bot closed this as completed Jul 2, 2022
@liss-bot liss-bot removed the ⚰️ Stale [ISSUE] [PR] No activity for over 1 month label Jul 2, 2022
@Lissy93
Copy link
Owner

Lissy93 commented Jul 2, 2022

I forgot to say, but this issue was fixed in #663

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug [ISSUE] Ticket describing something that isn't working 🕸️ Inactive
Projects
None yet
Development

No branches or pull requests

5 participants