Problem/Motivation
Replace Drupal login with Keycloak single sign-on (SSO) is not working feature is no working for keycloak client (See attached image)
Steps to reproduce
https://www.domainname.com/en/user/login, Instead of redirecting to the Keycloak server for authentication, it displayes default Drupal login page and a button "Log in with Keycloak".
see image attached
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | interdiff_3382665_fix_config_enabled_flag-3382665_17.diff | 1.74 KB | j-lee |
| #17 | 3382665-17.patch | 1.81 KB | j-lee |
| #7 | 3382665-7-fix-config-enabled-flag.diff | 1.38 KB | daniel.pernold |
| #6 | 3382665-fix-config-enabled-flag.diff | 786 bytes | daniel.pernold |
| userloginpage.png | 23.7 KB | hiralshah1991 |
Issue fork keycloak-3382665
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
colin.eininger commentedI was just investigating this.
First of all, the KeycloakService doesn't work anymore since OpenID Connect module switched from configuration to config entities. Instead of loading openid_connect.settings.keycloak config, it should load an active keycloak client like in OpenIDConnectLoginForm::submitForm
Same for the KeycloakController, it should load an active client and then execute the same code as OpenIDConnectLoginForm::submitForm. But when I tried this solution I got an exception :
This needs more investigating and test, but I don't have time to do so, hope this help.
Comment #3
hiralshah1991 commentedThanks colin.eininger,
I have also tried to update the Code for Keycloak module in similar manner but i am also reciveing the same error in the authorize function of "/keycloak/src/Plugin/OpenIDConnectClient/Keycloak.php"
I have made this changes because I need my application to auto redirect to SSO server's login page when "user/login" page of the app has been called
Changes i made were following
File: keycloak/src/Service/KeycloakService.php >>
Replace return $this->config->get('enabled'); with return $this->config->get('status'); (in isEnabled function)
Replaced protected const OPENID_CONNECT_CONFIG_NAME = 'openid_connect.settings.keycloak'; with protected const OPENID_CONNECT_CONFIG_NAME = 'openid_connect.client.keycloak'
File: keycloak/src/Controller/KeycloakController.php
Replaced $configuration = $this->config('openid_connect.settings.keycloak')->get('settings'); with $configuration = $this->config('openid_connect.client.keycloak')->get('settings');
File: keycloak/src/Plugin/OpenIDConnectClient/Keycloak.php
Replaced 'openid_connect_client' => $this->parentEntityId, with 'openid_connect_client' => 'keycloak',
But i end up receiving following error
"LogicException: The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\Core\Routing\TrustedRedirectResponse. in Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (line 154 of core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php)."
As i am new to Drupal I do not understand this what this error means though i tried the solution listed on internet for resolving such kind of erro but no luck.
Please help on this
Comment #4
bramdriesenThere is another issue open for this: #3107127: Can't get SingleSignOut to work
Where some more discussion about the topic happened. That one is also part of the roadmap to getting 2.x stable.
Comment #5
daniel.pernold commented@hiralshah1991 Your problem is this one:
https://www.drupal.org/project/keycloak/issues/3391108
in combination with this one:
https://www.drupal.org/node/2638686
Comment #6
daniel.pernold commentedThe problem here is the
OPENID_CONNECT_CONFIG_NAMEin combination with a missingenabledconfig as queried inKeycloakService::isEnabled(). I assume we have to change the implementation ofKeycloakService::isEnabled()to query thestatusconfig property. See attached 3382665-fix-config-enabled-flag.diff.Comment #7
daniel.pernold commentedRan into another problem in the
KeycloakControllerwhere the old setting is used. Here's the fix: 3382665-7-fix-config-enabled-flag.diffComment #8
daniel.pernold commented@hiralshah1991 I fixed your last problem directly in Keycloak without hacking core.
https://www.drupal.org/project/keycloak/issues/3396331
Comment #9
daniel.pernold commentedComment #10
bramdriesenComment #11
colin.eininger commentedAs I said earlier, OpenID Connect module module changed the way it stores configuration (from config to config entities) + The user can chose the configuration id.
So hard coding "openid_connect.client.keycloak" as #6 does is not the way to go I think. First of all, the controller would be aware of which config is actually used (e.g., putting the id of the config into the route path). This way we can give it to the service to use the right config.
I don't know in which case there can be multiple keycloak config on the same site, but It's actually possible and can be a use case (like multiple realms maybe ?).
An other idea: When the admin checks the option to replace the login page, then load a keycloak config with that option but in an undefined order (+ document this behavior) and use it.
Comment #12
bramdriesenExample:
- Agency X using keycloak for all their Devs
- Customer X using keycloak for all their users
It's a valid use case which we actually have on some projects. I've actually also worked once for a customer where they had two keycloak instances. One for their internal employees, and one for their external users/clients/customers.
Yeah, I guess we need to perhaps have the option to set a default one for when the replace drupal login option is selected. The others of course still need to be accessible by their own path on the site.
Comment #13
auth commentedThe issue https://www.drupal.org/project/keycloak/issues/3390391 implements support for multiple keycloak configurations and adds a global setting to choose which of the keycloak configurations that should be used to override the drupal login form.
Comment #14
saesa commented#7 give me the next error
Symfony\Component\Routing\Exception\InvalidParameterException: Parameter "openid_connect_client" for route "openid_connect.redirect_controller_redirect" must match "[^/]++" ("" given) to generate a corresponding URL. in Drupal\Core\Routing\UrlGenerator->doGenerate() (line 209 of core/lib/Drupal/Core/Routing/UrlGenerator.php).Comment #15
j-leeI have fixed #14 by changing
Drupal\keycloak\Controller\KeycloakController::login()as following:With this change, the client_id is set and the redirect is working.
Works with applying the patch form #7 and #3396331: LogicException when redirecting to Keycloak (#8)
Comment #16
j-leeNow, the next error appears: "Failed to start the session because headers have already been sent by "/app/vendor/symfony/http-foundation/Response.php" at line 1315."
See #3396331-9: LogicException when redirecting to Keycloak
Comment #17
j-leeI have added the changes from #15 to the patch from #7. It works with the latest 2.2.x branch.
Comment #18
j-leeAttach interdiff between #7 and #17.
Comment #19
j-leeAfter some investigation, it looks like that #3396331: LogicException when redirecting to Keycloak is not needed. The MR calls
$request->send()from there, which is done by Drupal itself.Comment #21
j-leeMR43 works for me. Can anyone check it?
Comment #22
profi248 commentedRedirect with MR43 seems to work properly for me with openid_connect 3.0.0-alpha5. But with the new alpha6 that came out in the meantime, I'm getting a new error: You have requested a non-existent service "openid_connect.openid_connect".
Comment #23
joseph.olstad#3506932-02: non-existent service "openid_connect.openid_connect" after update
@profi248, thanks for reporting, I'll notify the openid_connect folks that alpha6 caused this :
You have requested a non-existent service "openid_connect.openid_connect"Comment #24
joseph.olstad@profi248 , please test again alpha6 but apply this patch on openid_connect alpha6, possibly resolve the issue you reported.
https://www.drupal.org/files/issues/2025-02-17/openid_connect-revert-346...
Comment #25
joseph.olstad@profi248, update your build so that you get the full alpha6
now before you start using the site, run the hook updates
Ex:
drush updb -y;or
visite update.phpDid the schema updates run without error?
Now test again.
Comment #26
profi248 commented@joseph.olstad thanks for the reply.
This patch to openid_connect didn't apply for me, so I tried using MR144 from https://www.drupal.org/project/openid_connect/issues/3462532 instead. That, along with MR43 patch to keycloak did indeed fix the redirect problem, even on alpha6.
I also had to reinstall my local dev site after database migrations didn't work, but that seems to be a problem of me doing this on the same install before. When I started with a fresh install on keycloak 1.8.0 and openid_connect 1.4.0 and then ran the migrations, there were no issues.
Comment #27
profi248 commentedMR43 has been working well for me on our site. It would be great if we could get it merged into upstream. Let me know if you need any more testing.
Comment #28
j-leeWe have been using the changes from the MR for some time now without any problems.
However, setting my own MR as RTBC feels wrong :).
Can someone review it and comment accordingly?
Thank you very much.
Comment #30
joseph.olstadComment #32
joseph.olstadhttps://www.drupal.org/project/keycloak/releases/2.2.2
Comment #33
bramdriesenI updated the issue credits. Thanks everyone