Keycloak always redirecting to login page

2.7k views Asked by At

I´m using a keycloak instance to login in the frontend and secure the backend-api. After deployment on a linux machine on aws I faced a issue. I´m getting constantly redirected to the login page by accessing the api with a jwt token. Locally it´s working fine.

My client is a confidential client. I´m using client_id and _secret to authorize for the token call. The jwt token is valid and sucessfully generated. My implementation of the api works with expressJs and the keycloak-nodejs-connector:

    keycloakConfig = {
        serverUrl: 'https://keycloak.myserver.com/auth',
        realm: 'examplerealm',
        clientId: 'ui-client'
    };

   public init() {
        if (this.keycloak) {
            console.warn("Trying to init Keycloak again!");
            return this.keycloak;
        }
        else {
            console.log("Initializing Keycloak...");
            const memoryStore = new session.MemoryStore();
            // @ts-ignore
            this.keycloak = new Keycloak({ store: memoryStore }, this.keycloakConfig );
            return this.keycloak;
        }
    }

I could imagine that it is dependent on the current https setting. My nodejs api provides a endpoint for http and https (locally with a self signed certificate). On the server, where keycloak is running, I added a letsencrypt certificate with certbot and everything looks fine in the browser. Keycloak is started with the docker-container jboss/keycloak.

I´m curious to figure out my current issue and help is very appreciated :slight_smile: Let me know, if I missed to add necessary informations. Thanks in advance. Dominik

1

There are 1 answers

0
Dominik On

I found a solution for this. First I updated to the latest version of keycloak-connect. They provided a new major version 12 and it seems there was a change about the configuration.

Second there was a issue with the configuration. I digged into the current config object and figured out, that it should look like this:

keycloakConfig = {
    realm: 'test-realm',
    authServerUrl: 'https://myurl/auth/',
    realmPublicKey: 'key'
};