0

I have an angular 5 application in which I have implemented angular2-oauth-oidc with okta.

I am getting 400 Bad Request error saying Invalid_token when I tried to logout. It seems the session has been expired.

On clicking logout button the code used to logout is as follows:

this.oauthService.logOut();

My app.component.ts file:

this.oauthService.redirectUri = window.location.origin;
    this.oauthService.clientId = oktaClientId;
    this.oauthService.scope = 'openid profile email';
    this.oauthService.issuer = 'https://aaaa.oktapreview.com';
    this.oauthService.tokenValidationHandler = new JwksValidationHandler();
    this.oauthService.setupAutomaticSilentRefresh();

    // Load Discovery Document and then try to login the user
    this.oauthService.loadDiscoveryDocument().then(() => {
      this.oauthService.tryLogin({
        onTokenReceived: (info) => {
          this.router.navigate([info.state]);
        }
      });

Please help to handle logout, once the session has been expired. thanks in advance.

Jeroen
  • 60,696
  • 40
  • 206
  • 339
user3211705
  • 2,418
  • 3
  • 19
  • 36
  • Is the browser being redirected, and then you see 400 Bad Request as an error page? Or is the error showing up in the console? I've seen this before when the id_token isn't actually passed to the logout endpoint. Can you show the contents of the logout network request? – Nate Barbettini Dec 09 '17 at 01:50
  • For me, the browser redirects and displayed 400 Bad Request error is displayed. In console, I found the id_token is passed in oauth request. – user3211705 Dec 09 '17 at 12:42
  • Does it always cause 400 Bad Request, or only after waiting a long time (so the session expires)? What if you update the issuer to `https://aaaa.oktapreview.com/oauth2/default`? – Nate Barbettini Dec 11 '17 at 18:51
  • It occurs only after waiting for a long time. – user3211705 Dec 12 '17 at 04:08
  • Make sure you have a Logout Redirect URI registered for your app on Okta. It should probably match your Login Redirect URI. – Matt Raible Dec 13 '17 at 16:39
  • @user3211705 I got the same problem. How can you solve this one. – Daniel Pham Jun 26 '20 at 04:03

0 Answers0