+
Skip to content

Why logout on close()? #168

@iliuta

Description

@iliuta

Describe the bug

Hi,

I noticed in 26.0.5 we have the following commit:

57ad090#diff-4af001d12faa275e01ea6aedd4f1c592cd7f3d962edc25e5b17fe294dc9fc7f3R177-R183

with the following code change in Keycloak.java

    public void close() {Add commentMore actions
        closed = true;
        if (tokenManager != null) {
            try {
                tokenManager.logout();
            } catch (RuntimeException e) {
                // do our best closing the session but logout can fail because multiple reasons:
                // shared jakarta client closed, realm removed or disabled, client removed or disabled,...
            }
        }
        client.close();
    }

In our code, we use a try with resources on a Keycloak instance for obtaining access and refresh tokens using password grant flow.

Since Keycloak is an AutoCloseable, because of try with resources the close() method is called after the tokens are obtained, therefore the logout occurs, therefore the refresh token is no longer valid (no session).

Can you explain why you've introduced this logout bevahiour on close(), please?

Version

admin client 26.0.5 (Keycloak core 26.2.5, Keycloak 26.2.5)

Expected behavior

Maybe the the session should not be logged out on close().

Actual behavior

In our code, we use a try with resources on a Keycloak instance for obtaining access and refresh tokens using password grant flow.

Since Keycloak is an AutoCloseable, because of try with resources the close() method is called after the tokens are obtained, therefore the logout occurs, therefore the refresh token is no longer valid (no session).

How to Reproduce?

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载