Programmatic keycloak.json

Hi,

Is it possible to skip the keycloak.json file? I’m trying to configure KeycloakInstalled with code like the following on Keycloak 15.0.2 in a desktop client.

AdapterConfig ac = new AdapterConfig();
ac.setAuthServerUrl("http://localhost:8180/auth");

KeycloakDeployment kd = new KeycloakDeployment();
kd.setRealm("myrealm");
kd.setAuthServerBaseUrl(ac);
kd.setSslRequired(SslRequired.EXTERNAL);
kd.setResourceName("myrez");
kd.setPublicClient(true);
kd.setUseResourceRoleMappings(true);
kd.setPkce(true);

KeycloakInstalled keycloak = new KeycloakInstalled(kd);

keycloak.loginDesktop();

However, I get an NPE at org.keycloak.adapters.installed.KeycloakInstalled.createAuthUrl(KeycloakInstalled.java:238)

If I use the file keycloak.json, everything works well. I figure I can form a JSON string and pass it into Keycloak installed, but I was wondering if there was a way to use the API.

-Carl

This is working for me, but please reply if you know of a way to use the API for type safety.

Thanks

    Map<String, String> config = Map.of(
            "realm", "myrealm",
            "auth-server-url", "http://localhost:8180/auth",
            "ssl-required", "external",
            "resource", "myrez",
            "public-client", "true",
            "use-resource-role-mappings", "true",
            "enable-pkce", "true"
    );

    Type configType = new TypeToken<Map<String, String>>() {}.getType();

    String configJson = new Gson().toJson(config, configType);

    KeycloakInstalled keycloak = new KeycloakInstalled(new ByteArrayInputStream(configJson.getBytes()));

    keycloak.loginDesktop();