angular-auth-oidc-client logout not working

8.6k views Asked by At

I am using angular-auth-oidc-client lib for authenticating my app with keycloak as the identity server.i am able to login into the app however the logout functionality is not working. I've read the docs and am using the same call for logout but it doesn't seem to work. Please help. Thanks in advance.

Here is my config:

{
    "sts_server": "http://localhost/auth/realms/test",
    "redirect_url": "http://localhost:4200/app/",
    "client_id": "test_client",
    "response_type": "code",
    "scope": "openid profile email",
    "post_logout_redirect_uri": "http://localhost:4200/app/#/homepage/",
    "startup_route": "/homepage/welcome",
    "start_checksession": "true",
    "silent_renew": "true",
    "silent_renew_url": "assets",
    "max_id_token_iat_offset_allowed_in_seconds": "10",
    "logLevel": "info",
    "forbidden_route": "/unauthorized",
    "unauthorized_route": "/unauthorized"
}

My logout method:

  logOut() {
        this.oidcSecurityService.logoffLocal();
        this.oidcSecurityService.logoffAndRevokeTokens();
        this.oidcSecurityService.logoff();
// none of the three mentioned above work.
    
      }
3

There are 3 answers

2
Mateusz Kaleta On

You have to subscribe to this methods.

 this.sercurityService.logoff().subscribe((result) => {
      // any
    });

0
Rob Audenaerde On

No solution, but more info:

enter image description here

It looks like the call to /logout is cancelled. However, if I paste that into the browser, it does log me out, so the url and functionality seem ok.

More info:

In my scenario, the page with the logout-button and logic is behind a guard. My theory is that because of the logout-login, the page with the button is no longer available and thus the call to logout is cancelled, in effect staying logged in and returned to the current URL.

0
LeoL On

Firs of all check if the logout call gets cancelled in the network tab of your browser. If you see this behavior and you have the logout functionality inside an a element, try to remove href if you have it. Worked for me.