camunda-community-hub / camunda-platform-7-keycloak

Camunda Keycloak Identity Provider Plugin
Apache License 2.0
132 stars 74 forks source link

Camunda/ Keycloak logout is not working correctly for Keycloak 18 or above. #101

Closed aloksingh25 closed 2 years ago

aloksingh25 commented 2 years ago

login is success but when logging out from Camunda, it's not working with code given in : examples/sso-kubernetes/src/main/java/org/camunda/bpm/extension/keycloak/showcase/sso/KeycloakLogoutHandler.java

image

Redirect logout URL: http://localhost:8180/realms/master/protocol/openid-connect/logout?redirect_uri=http://localhost:8082

Camunda 7.17 Keyclock 18.0.0

VonDerBeck commented 2 years ago

Hi @aloksingh25,

can you tell me more about your setup? Logout has been working correctly with the sample checked in.

Gunnar

aloksingh25 commented 2 years ago

Hi Gunnar, Please find the details below.

Note: Login is working fine. Even if you notice in yaml "auth" keyword is removed from the URLs for Keyclock 18 and 19. plugin.identity.keycloak: keycloakIssuerUrl: http://localhost:8180/auth/realms/master Regards, Alok Singh Principal Consultant Modernization Practice, Infosys M: 997 123 7696 @.**@. Upcoming Planned Leave(s): NA

From: Gunnar von der Beck @.> Sent: Friday, August 26, 2022 8:47 PM To: camunda-community-hub/camunda-platform-7-keycloak @.> Cc: Alok Singh @.>; Mention @.> Subject: Re: [camunda-community-hub/camunda-platform-7-keycloak] Camunda/ Keyclock logout is not working correctly. (Issue #101)

[EXTERNAL EMAIL]

Hi @aloksingh25https://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Faloksingh25&data=05%7C01%7Calok.singh25%40infosys.com%7C98420fffce734b79e99b08da87763621%7C63ce7d592f3e42cda8ccbe764cff5eb6%7C0%7C0%7C637971239057705892%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=JmDZ0uMb29vln2P3nYEYLc22V57Ix93DY6WfRwl9RII%3D&reserved=0,

can you tell me more about your setup? Logout has been working correctly with the sample checked in.

Gunnar

- Reply to this email directly, view it on GitHubhttps://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcamunda-community-hub%2Fcamunda-platform-7-keycloak%2Fissues%2F101%23issuecomment-1228624595&data=05%7C01%7Calok.singh25%40infosys.com%7C98420fffce734b79e99b08da87763621%7C63ce7d592f3e42cda8ccbe764cff5eb6%7C0%7C0%7C637971239057705892%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=bQCFhwlXC47vRT5jtzoTnCH4nCrWeii8UeR3iIF6gbo%3D&reserved=0, or unsubscribehttps://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAPI2CJV5GR2R2MDNJ54LI6LV3DNYDANCNFSM57THAHBA&data=05%7C01%7Calok.singh25%40infosys.com%7C98420fffce734b79e99b08da87763621%7C63ce7d592f3e42cda8ccbe764cff5eb6%7C0%7C0%7C637971239057705892%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=CdPsZUwJdP9vyzHA7cA06LGYKsiL2gEJOB1MJ01fU4U%3D&reserved=0. You are receiving this because you were mentioned.Message ID: @.**@.>>

VonDerBeck commented 2 years ago

@aloksingh25: Indeed, you're right: starting with Keycloak 18 there are some changes when it comes to the logout procedure. See https://www.keycloak.org/2022/04/keycloak-1800-released / Chapter "OpenID Connect Logout". The current sample is - not yet - adapted to that. What you can do is one of the following:

I will modify and update the sample in future, propably when Camunda 7.18 is released. Does that help?

Gunnar

aloksingh25 commented 2 years ago

Hi Gunnar,

Regards, Alok Singh Principal Consultant Modernization Practice, Infosys M: 997 123 7696 @.**@. Upcoming Planned Leave(s): NA

From: Gunnar von der Beck @.> Sent: Monday, August 29, 2022 5:19 PM To: camunda-community-hub/camunda-platform-7-keycloak @.> Cc: Alok Singh @.>; Mention @.> Subject: Re: [camunda-community-hub/camunda-platform-7-keycloak] Camunda/ Keyclock logout is not working correctly. (Issue #101)

[EXTERNAL EMAIL]

@aloksingh25https://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Faloksingh25&data=05%7C01%7Calok.singh25%40infosys.com%7C0133ab1f7f324978463a08da89b4a094%7C63ce7d592f3e42cda8ccbe764cff5eb6%7C0%7C0%7C637973706146585890%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Y6UfcV0pDnso7hZNc0SMj%2BwRTvdMVLszj08pSd%2Ftqno%3D&reserved=0: Indeed, you're right: starting with Keycloak 18 there are some changes when it comes to the logout procedure. See https://www.keycloak.org/2022/04/keycloak-1800-releasedhttps://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.keycloak.org%2F2022%2F04%2Fkeycloak-1800-released&data=05%7C01%7Calok.singh25%40infosys.com%7C0133ab1f7f324978463a08da89b4a094%7C63ce7d592f3e42cda8ccbe764cff5eb6%7C0%7C0%7C637973706146585890%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=TdRqicY8CX0m7SKL6xRMh6d0BFg%2B%2B2S1q8YOWSjJySM%3D&reserved=0 / Chapter "OpenID Connect Logout". The current sample is - not yet - adapted to that. What you can do is one of the following:

I will modify and update the sample in future, propably when Camunda 7.18 is released. Does that help?

Gunnar

- Reply to this email directly, view it on GitHubhttps://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcamunda-community-hub%2Fcamunda-platform-7-keycloak%2Fissues%2F101%23issuecomment-1230179038&data=05%7C01%7Calok.singh25%40infosys.com%7C0133ab1f7f324978463a08da89b4a094%7C63ce7d592f3e42cda8ccbe764cff5eb6%7C0%7C0%7C637973706146585890%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=XReMMgcjU2bho7jPYyMp8T%2Bug8I5c0ktImPuE7OK6us%3D&reserved=0, or unsubscribehttps://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAPI2CJQQX3F63VHKJ2SVHZLV3SPTVANCNFSM57THAHBA&data=05%7C01%7Calok.singh25%40infosys.com%7C0133ab1f7f324978463a08da89b4a094%7C63ce7d592f3e42cda8ccbe764cff5eb6%7C0%7C0%7C637973706146585890%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=pA2wqpXk4epg%2FeiH0HKGDsYxUYaf9BAT6Kg%2BrW7q7bA%3D&reserved=0. You are receiving this because you were mentioned.Message ID: @.**@.>>

VonDerBeck commented 2 years ago

Hi @aloksingh25,

so please do the following:

1.) Please be aware that in Keycloak you now have to additionally configure "Valid post logout redirect URIs" 2.) Within the existing Keycloak Logout Handler just change the logoutUrl as follows:

// Complete logout URL
String logoutUrl = oauth2UserLogoutUri + "?post_logout_redirect_uri=" + redirectUri + "&id_token_hint=" + ((OidcUser)authentication.getPrincipal()).getIdToken().getTokenValue();

That should do the trick.

Cheers Gunnar

aloksingh25 commented 2 years ago

Hi Gunnar, With the below option, redirect is still failing at Camunda app's. Sharing below snaps.

Complete logout URL: (I can see keyclock session is getting expired with the below URL.) http://localhost:8180/realms/master/protocol/openid-connect/logout?redirect_uri=http://localhost:8082&id_token_hint=eyJhbGciOiJSUzI1NiIsInR5cCIgOiAi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CFnob0SOASF35EsBWbO1HKA9D274SNIeKwztAcwKkrHkmPLA8KVsOYgUt4Zc3xNMCSbG3n-O840ZQRDj0kgdShQ-y-CqV5C10QtLX8JhMfa1hAZHwSF4O94h0We7ROq94L3LPsGHnN9JL7vSK80pGxNA5OHQ4PRzjyMkseXWa7UbDvziXKnOLoLZ33NSfaXggbmcUL0Pw

Logout handler: @.***

Keyclock' logout URIs @.***

Regards, Alok Singh Principal Consultant Modernization Practice, Infosys M: 997 123 7696 @.**@. Upcoming Planned Leave(s): NA

From: Gunnar von der Beck @.> Sent: Monday, August 29, 2022 8:36 PM To: camunda-community-hub/camunda-platform-7-keycloak @.> Cc: Alok Singh @.>; Mention @.> Subject: Re: [camunda-community-hub/camunda-platform-7-keycloak] Camunda/ Keyclock logout is not working correctly. (Issue #101)

[EXTERNAL EMAIL]

Hi @aloksingh25https://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Faloksingh25&data=05%7C01%7Calok.singh25%40infosys.com%7Cc40749aa83124741e92808da89d0607a%7C63ce7d592f3e42cda8ccbe764cff5eb6%7C0%7C0%7C637973825325531026%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=79oapK1NGwNnlU8JeKXxniJ06JSOBP5WXlDXSDK%2B8lY%3D&reserved=0,

so please do the following:

1.) Please be aware that in Keycloak you now have to additionally configure "Valid post logout redirect URIs" 2.) Within the existing Keycloak Logout Handler just change the logoutUrl as follows:

// Complete logout URL

String logoutUrl = oauth2UserLogoutUri + "?post_logout_redirect_uri=" + redirectUri + "&id_token_hint=" + ((OidcUser)authentication.getPrincipal()).getIdToken().getTokenValue();

- Reply to this email directly, view it on GitHubhttps://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcamunda-community-hub%2Fcamunda-platform-7-keycloak%2Fissues%2F101%23issuecomment-1230440913&data=05%7C01%7Calok.singh25%40infosys.com%7Cc40749aa83124741e92808da89d0607a%7C63ce7d592f3e42cda8ccbe764cff5eb6%7C0%7C0%7C637973825325531026%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=2EIICqPSFXpR4Nmre6eGr%2BATKzOMWkzAwJ%2BC%2BIgKilo%3D&reserved=0, or unsubscribehttps://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAPI2CJUU7TMQ6KM4YJBDIW3V3TGUNANCNFSM57THAHBA&data=05%7C01%7Calok.singh25%40infosys.com%7Cc40749aa83124741e92808da89d0607a%7C63ce7d592f3e42cda8ccbe764cff5eb6%7C0%7C0%7C637973825325531026%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=MUjIZ6KAgY1OxXgSmbA%2FCOpjA0h6OWv3u9Qsp87EmBo%3D&reserved=0. You are receiving this because you were mentioned.Message ID: @.**@.>>

VonDerBeck commented 2 years ago

Hi @aloksingh25,

can you please stop repyling by mail?? This is absolutely unreadable.

Please share your qestion and content in a format so that I can read it on GitHub. Otherwise I will close this issue as "not reproducible". Sorry for being that harsh. Just look at your comments directly on github.com - its disrespectful towards me investing my rare time!

Back to your problem: what will happen upon logout is: you'll get logged out from Keycloak. Keycloak sends a redirect to your app to Camunda Cockpit. And because you're not logged in, this will redirect you back to the login page of Keycloak.

This works with Keycloak 19.0.1, Keycloak config for "Valid post logout redirect URIs", adjusted Keycloak URIs (without "auth") in the application.yaml config and the simple change to the logout handler posted above.

Gunnar