Repository navigation
Add per-application session termination to Account Console - #47922
Conversation
|
There are CI failures but they appear to be unrelated to this PR. If you think otherwise, happy to investigate and fix. |
|
Marking this PR as "hold" as it IMHO needs more discussion in the parent issue. |
5826db5 to
b001062
Compare
|
@ahus1 the PR is updated as discussed in #47921: Could you take another look and remove the hold if this addresses your concerns? |
Unreported flaky test detectedIf the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR. org.keycloak.testsuite.webauthn.registration.passwordless.PwdLessOtherSettingsTest#timeout |
There was a problem hiding this comment.
Thank for the changes. All discussed items are now included.
Looking at in more detail, I found that regular sessions are handled differently than offline session. This is something we want to avoid nowadays, as users don't know the difference, and things should behave the same.
I've pushed a change in the application logic. Please have a look if you agree. If you agree, please update the test cases.
I've removed the Turkish translation for now: It is usually managed in Weblate. When doing changes in the pull requests and in Weblate, this leads now and then to conflicts. With that, I ask you defer the translation to Turkish to when this PR is merged, and then apply the changes in Weblate frontend.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Suppressed comments (7)
services/src/main/java/org/keycloak/services/resources/account/AccountRestService.java:419
- This concatenates offline sessions, so the endpoint detaches offline client sessions even though the API contract explicitly says offline access is unaffected. Restrict the stream to online user sessions and add an offline-only regression case.
Stream.concat(session.sessions().getUserSessionsStream(realm, user), session.sessions().getOfflineUserSessionsStream(realm, user))
js/apps/account-ui/src/applications/Applications.tsx:205
- This exposes the action for offline-only applications, where there is no online session to end and offline access must remain unaffected. Gate the action solely on
inUse; the existing visibility test should includeofflineAccess: trueto cover this case.
{(application.inUse || application.offlineAccess) &&
js/apps/account-ui/src/applications/Applications.tsx:202
offlineAccessmeans an offline grant exists, not that an online application session is active. Including it here marks offline-only applications as “In use,” contradicting the backend representation and the documented status semantics.
This issue also appears on line 205 of the same file.
{(application.inUse || application.offlineAccess) ? t("inUse") : t("notInUse")}
services/src/main/java/org/keycloak/services/resources/account/AccountRestService.java:396
- This first sentence contradicts both the final sentence and the implemented API contract: offline sessions are intentionally excluded.
This issue also appears on line 419 of the same file.
* Ends all active online and offline sessions of the user for the client with the given client id.
js/apps/account-ui/src/api/methods.ts:112
- Encode the client ID before interpolating it into the URL. Valid client IDs can contain URL delimiters (for example URI-shaped SAML client IDs), which currently changes the path/query instead of addressing that client;
deleteConsentdirectly above already follows this pattern.
return request(`/applications/${clientId}/sessions`, context, {
js/apps/account-ui/maven-resources/theme/keycloak.v3/account/messages/messages_en.properties:61
- The PR states that Turkish translations are included, but
maven-resources-community/theme/keycloak.v3/account/messages/messages_tr.propertieshas none of these new keys, so Turkish users fall back to English. Add the corresponding Turkish entries or update the stated scope.
endApplicationSession=End application session
endApplicationSessionSuccess=Ended the application session for {{name}}
endApplicationSessionError=Could not end the application session due to\: {{error}}
endApplicationSessionMessage=This ends your active sessions with {{name}}. If your account session is still active, the application might sign you in again automatically without asking for credentials.
services/src/main/java/org/keycloak/services/resources/account/AccountRestService.java:415
- Use the standardized event error metadata here. The adjacent client lookup in
revokeConsentrecords the rendered message asDetails.REASONandErrors.CLIENT_NOT_FOUNDas the error code (lines 383-385); storing the whole message as the code prevents reliable event aggregation.
event.error(msg);
83c1016 to
57b81dc
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Offline sessions are revoked contrary to scope, Turkish translations are missing, and client-not-found events use a nonstandard error value.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (3)
Previously missed (1) — in code that hasn't changed since the last review.
services/src/main/java/org/keycloak/services/resources/account/AccountRestService.java:415
EventBuilder.errorstores its argument as the machine-readable event error, so using the user-supplied message creates inconsistent, high-cardinality error values. Match the adjacent account endpoints by recording the message asDetails.REASONand usingErrors.CLIENT_NOT_FOUND(see lines 382-386 and 490-494).
services/src/main/java/org/keycloak/services/resources/account/AccountRestService.java:421
- This stream explicitly includes offline sessions, contradicting both the PR description and issue #47921's non-goal that offline-token revocation remains the existing Remove access operation. Restrict this endpoint to online user sessions so ending an application session does not also revoke offline access.
Stream.concat(session.sessions().getUserSessionsStream(realm, user), session.sessions().getOfflineUserSessionsStream(realm, user))
.filter(userSession -> userSession.getAuthenticatedClientSessionByClient(client.getId()) != null)
.toList() // collect to avoid concurrent modification.
js/apps/account-ui/src/applications/Applications.tsx:208
- This exposes End application session for offline-only applications, which turns the new action into the existing offline-access revocation flow and contradicts the stated non-goal. Only
application.inUseshould control this action.
{(application.inUse || application.offlineAccess) &&
application.clientId !== context.environment.clientId && (
- Files reviewed: 7/7 changed files
- Comments generated: 4
- Review effort level: Balanced
Unreported flaky test detectedIf the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR. org.keycloak.testsuite.adapter.servlet.SAMLServletAdapterTest#employeeSigPostNoIdpKeyTestCertSubjectAsKeyNameInKeyInfoKeycloak CI - Adapter IT Strict Cookies |
|
Build is failing due to #52283, let's wait for that to be fixed first. |
Allow users to end their active sessions with an individual application
from the Applications page. Applications with an active session show an
"End application session" action, backed by a new account REST API
endpoint DELETE /applications/{clientId}/sessions.
The endpoint detaches the client sessions from the user's online
sessions, notifying the client via backchannel logout when supported,
and removes user sessions that no longer have any client sessions.
Offline sessions are not affected. The Account Console itself does not
offer the action for its own client.
Closes keycloak#47921
Signed-off-by: Muhammed Oguz <muhammed@keymate.io>
Signed-off-by: Alexander Schwartz <alexander.schwartz@gmx.net>
Signed-off-by: Alexander Schwartz <alexander.schwartz@gmx.net>
Align offline session cleanup with online sessions: when the last client session of an offline user session is ended, remove the offline user session via removeOfflineUserSession instead of the online-only removeUserSession. Add API tests for offline and mixed online/offline revocation, a UI test for offline-only applications, and update the docs and confirmation message to reflect that offline sessions are ended. Signed-off-by: Muhammed Oguz <muhammed@keymate.io>
…types Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
969f4ab to
8d5b735
Compare
There was a problem hiding this comment.
🟡 Changes recommended
HTTP failures are reported as successful, and the documentation incorrectly claims issued access tokens are revoked.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 4
- Review effort level: Balanced
Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
| event.event(EventType.LOGOUT); | ||
| ClientModel client = realm.getClientByClientId(clientId); | ||
| if (client == null) { | ||
| // Return 204 instead of 404 to prevent client enumeration via this endpoint. | ||
| String msg = String.format("No client with clientId: %s found.", clientId); | ||
| event.detail(Details.REASON, msg); | ||
| event.error(Errors.CLIENT_NOT_FOUND); | ||
| return Response.noContent().build(); | ||
| } |
|
|
||
| ==== Ending an application session | ||
|
|
||
| You can end your active sessions with a specific application directly from the *Applications* page. Applications that have an active session are marked as *In use* and display an *End application session* button. The Account Console itself does not display this button. |
| {application.inUse || application.offlineAccess | ||
| ? t("inUse") | ||
| : t("notInUse")} |
| Stream.concat(session.sessions().getUserSessionsStream(realm, user), session.sessions().getOfflineUserSessionsStream(realm, user)) | ||
| .filter(userSession -> userSession.getAuthenticatedClientSessionByClient(client.getId()) != null) | ||
| .toList() // collect to avoid concurrent modification. | ||
| .forEach(userSession -> { |
| List<ClientRepresentation> applications = simpleHttp | ||
| .doGet(getAccountUrl("applications")) | ||
| .header("Accept", "application/json") | ||
| .auth(token) | ||
| .asJson(new TypeReference<List<ClientRepresentation>>() { | ||
| }); |
| applications = simpleHttp | ||
| .doGet(getAccountUrl("applications")) | ||
| .header("Accept", "application/json") | ||
| .auth(token) | ||
| .asJson(new TypeReference<List<ClientRepresentation>>() { | ||
| }); |
Summary
Allow users to end their active sessions with an individual application on the Applications page in the Account Console.
The Applications page shows which applications have active sessions ("In use") but provides no way to end those sessions. This adds an End application session action for in-use applications, backed by a new Account REST API endpoint. Naming follows the discussion in #47921.
Closes #47921
Changes
Backend
DELETE /applications/{clientId}/sessionsendpoint inAccountRestService, requiring themanage-accountrole (consistent with the existing session endpoints)LOGOUTevent with arevoked_clientdetail is emitted per affected session, consistent with the Device Activity endpointsTokenRevocationEndpoint404for an unknown client,403withoutmanage-account; the operation is idempotent (204when there is nothing to end)Frontend
Tests
tests/base), following the migration ofAccountRestServiceTestin Migrate the AccountRestServiceTest #49296:404for an unknown client403withoutmanage-accountDocumentation
Translations
Screenshots
Discussion
#47920