I've got a problem with Keycloak java adapter. I try to integrate desktop application with Keycloak and enable SSO between a few other web applications. The problem is that when I try to login to Keycloak everything works perfect and smooth, I get information about proper authentication, obtain token and can even parse it without any problem, but there is no session created in WebBrowser (no session, no cookies). This means that I can't use just created session with other apps in same Keycloak realm, even if session in Keycloak is created properly.
What's more cookies created and stored earlier by other applications are also deleted (as cookies I mean KEYCLOAK_IDENTITY and KEYCLOAK_INDENTITY_LEGACY) after "succesful" login attempt with my desktop adapter. When I inspect browser cookies, there is some warning statement saying that cookies are rejected cause of their expiration.
What I use is KeycloakInstalled adapter (in latest, 15.0.2 version). I configured it using instruction on the page: https://www.keycloak.org/docs/latest/securing_apps/
The most important piece of code in this case in my opinion:
KeycloakInstalled keycloak = new KeycloakInstalled();
AdapterConfig config = new AdapterConfig();
Map<String, Object> credentials = new HashMap<String, Object>();
credentials.put("secret", secret);
config.setAuthServerUrl(url);
keycloak.getDeployment().setRealm(realm);
keycloak.getDeployment().setAuthServerBaseUrl(config);
keycloak.getDeployment().setResourceName(resource);
keycloak.getDeployment().setResourceCredentials(credentials);
keycloak.getDeployment().setClientAuthenticator(ClientCredentialsProviderUtils.bootstrapClientAuthenticator(keycloak.getDeployment()));
keycloak.loginDesktop();
In this case some Keycloak properties are set statically in keycloak.json file and some dynamically in Java (example above). In keycloak.json file, some properties like realm, auth-server-url, resource and secret are filled with junk data, just to be, because they are set later dynamically.
{
"realm": "<realm>",
"auth-server-url": "<url>",
"ssl-required": "external",
"resource": "<keycloak-client>",
"use-resource-role-mappings": true,
"credentials" : {
"secret" : "abc"
},
"truststore" : "<file>.jks",
"truststore-password" : "<password>"
}
Keycloak's client configuration I've set like this:
How can I avoid deleting session cookies with my desktop adapter?