8000 Add per-application session termination to Account Console by muhammedogz · Pull Request #47922 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Add per-application session termination to Account Console - #47922

Merged
ahus1 merged 8 commits into
keycloak:mainfrom
muhammedogz:account-console-app-session-termination
Sep 3, 2026
Merged

ahus1 merged 8 commits into
keycloak:mainfrom
muhammedogz:account-console-app-session-termination

Conversation

@muhammedogz
@muhammedogz muhammedogz commented Apr 9, 2026 •
Copy link
Copy Markdown
Contributor

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

  • New DELETE /applications/{clientId}/sessions endpoint in AccountRestService, requiring the manage-account role (consistent with the existing session endpoints)
  • For each of the user's online sessions that has a client session for the application:
    • The client session is detached and the client is notified via backchannel logout when supported
    • A LOGOUT event with a revoked_client detail is emitted per affected session, consistent with the Device Activity endpoints
    • A user session left without any client sessions afterwards is removed, consistent with TokenRevocationEndpoint
  • Offline sessions are included as well after the discussion
  • 404 for an unknown client, 403 without manage-account; the operation is idempotent (204 when there is nothing to end)

Frontend

  • End application session action on the Applications page for applications marked "In use"
  • The Account Console does not offer the action for its own client: ending the current client session is effectively a no-op (the user is signed in again silently), which would be confusing
  • The confirmation modal describes the actual behavior: the sessions end, but the application might sign the user in again automatically while the browser session is still active

Tests

  • 4 API tests in the new test framework (tests/base), following the migration of AccountRestServiceTest in Migrate the AccountRestServiceTest #49296:
    • Happy path, including the per-session logout event and the removal of the emptied user session
    • 404 for an unknown client
    • 403 without manage-account
    • Idempotency
  • 2 Playwright UI tests using route mocking (same pattern as the existing sorting test):
    • The end-session flow
    • The action visibility rules

Documentation

  • Server Admin guide: new Ending an application session section describing the actual semantics

Translations

  • Turkish translations will be handled later via Weblate

Screenshots

02-applications-in-use 03-confirm-modal 04-success-alert

Discussion

#47920

@muhammedogz
Copy link
Copy Markdown
Contributor Author

There are CI failures but they appear to be unrelated to this PR. If you think otherwise, happy to investigate and fix.

@ahus1 ahus1 added the status/hold PR should not be merged. On hold for later. label Apr 10, 2026
@ahus1
ahus1 commented Apr 10, 2026
Copy link
Copy Markdown
Member

Marking this PR as "hold" as it IMHO needs more discussion in the parent issue.

@muhammedogz
muhammedogz force-pushed the account-console-app-session-termination branch from 5826db5 to b001062 Compare August 10, 2026 01:30
Copilot AI balanced review requested due to automatic review settings August 10, 2026 01:30
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@muhammedogz
Copy link
Copy Markdown
Contributor Author

@ahus1 the PR is updated as discussed in #47921:
the action is renamed to "End application session", the endpoint semantics are aligned with your description there (details in the issue and the updated PR description), and the branch is rebased onto main with the API tests migrated to the new test framework.

Could you take another look and remove the hold if this addresses your concerns?

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If 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

Keycloak CI - WebAuthn IT

org.openqa.selenium.WebDriverException: 
unknown error: unhandled inspector error: {"code":-32000,"message":"Node with given id does not belong to the document"}
  (Session info: chrome=150.0.7871.128)
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.17.0-1020-azure', java.version: '25.0.3'
...

Report flaky test

@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unreported flaky test detected, please review

Copilot AI review requested due to automatic review settings August 10, 2026 08:12
@ahus1 ahus1 removed the status/hold PR should not be merged. On hold for later. label Aug 10, 2026
@ahus1 ahus1 left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 include offlineAccess: true to cover this case.
                    {(application.inUse || application.offlineAccess) &&

js/apps/account-ui/src/applications/Applications.tsx:202

  • offlineAccess means 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; deleteConsent directly 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.properties has 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 revokeConsent records the rendered message as Details.REASON and Errors.CLIENT_NOT_FOUND as the error code (lines 383-385); storing the whole message as the code prevents reliable event aggregation.
            event.error(msg);

@muhammedogz
muhammedogz force-pushed the account-console-app-session-termination branch from 83c1016 to 57b81dc Compare August 31, 2026 15:36
@ahus1 ahus1 self-assigned this Sep 1, 2026
Copilot AI review requested due to automatic review settings September 2, 2026 08:05
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.error stores 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 as Details.REASON and using Errors.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.inUse should 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

@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If 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#employeeSigPostNoIdpKeyTestCertSubjectAsKeyNameInKeyInfo

Keycloak CI - Adapter IT Strict Cookies

org.opentest4j.AssertionFailedError: expected: <true> but was: <false>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertTrue.failNotTrue(AssertTrue.java:63)
	at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:36)
...

Report flaky test

@ahus1
ahus1 commented Sep 2, 2026
Copy link
Copy Markdown
Member

Build is failing due to #52283, let's wait for that to be fixed first.

muhammedogz and others added 5 commits September 2, 2026 15:49
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>
@ahus1
ahus1 force-pushed the account-console-app-session-termination branch from 969f4ab to 8d5b735 Compare September 2, 2026 13:49
Copilot AI review requested due to automatic review settings September 2, 2026 13:49
Copilot AI left a comment
10BC8 Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread js/apps/account-ui/src/api/methods.ts Resolved
Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
Copilot AI review requested due to automatic review settings September 2, 2026 14:51
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread js/apps/account-ui/src/api/methods.ts Resolved
Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
Copilot AI review requested due to automatic review settings September 2, 2026 15:30
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +411 to +419
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.
Comment on lines +202 to +204
{application.inUse || application.offlineAccess
? t("inUse")
: t("notInUse")}
Comment on lines +421 to +424
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 -> {
Comment on lines +1303 to +1308
List<ClientRepresentation> applications = simpleHttp
.doGet(getAccountUrl("applications"))
.header("Accept", "application/json")
.auth(token)
.asJson(new TypeReference<List<ClientRepresentation>>() {
});
Comment on lines +1336 to +1341
applications = simpleHttp
.doGet(getAccountUrl("applications"))
.header("Accept", "application/json")
.auth(token)
.asJson(new TypeReference<List<ClientRepresentation>>() {
});
@ahus1
ahus1 enabled auto-merge (squash) September 2, 2026 16:27
@ahus1
ahus1 merged commit 033c481 into keycloak:main Sep 3, 2026
102 of 104 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Account Console: Add per-application session termination on the Applications page

4 participants

0