question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

implicit flow logout not working

See original GitHub issue

I am using this library to implement the implicit flow. I have successfully implemented the implicit flow and it all works fine. My website is automatically redirecting to the oauth server. After i login successfully i get redirected to my website. I get the access_token and can work with it. It all works fine, but when i click on logout and call oauthService.logOut(); i will not be redirected to the oauth login page. The local storage and its tokens are getting deleted after the logOut() call, but the oauth server still has its informations. So when i click logout, the tokens will disappear but no redirect happens. When i refresh the page, my application automatically gets the valid token from the oauth server again and i stay logged in. I tried to set a logoutUrl in my auth-configs, but it does not matter if there is one in the configs and i also played with false and true paramter of logOut() method. Nothing changes.

This is my login and logout method and this are my auth configs:

loginUrl: 'https://test.azurewebsites.de/oauth/authorize',
  logoutUrl: 'https://test.azurewebsites.de/oauth/logout',
  redirectUri: window.location.origin+"/index.html",
  clientId: 'test',
  scope: 'write',
  oidc: false,
  responseType: 'token'
login(targetUrl?: string): Promise<void> {
    let validToken = this.oauthService.hasValidAccessToken();

    return this.oauthService.tryLogin()
      .then(() => {
        if (!validToken) {
          this.oauthService.initImplicitFlow(encodeURIComponent(targetUrl || this.router.url));
          return Promise.resolve();
        } else {
          this.isAuthenticatedSubject$.next(validToken);
          this.initTokenData(this.oauthService.getAccessToken());
          return Promise.resolve();
        }
      }).then(() => {
        this.isDoneLoadingSubject$.next(true);
      }).catch(e => {
        console.log("ERROR: ", e);
        this.isDoneLoadingSubject$.next(true);
        return Promise.reject(e);
      });
  }

  logout() {
    this.oauthService.logOut(false);
    this._tokenData = null;
  }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
jeroenheijmanscommented, Jan 28, 2019

Huh, strange. With this.oauthService.logOut(false) you should in fact get sent to the log out URL. It should be easy enough to see why it doesn’t work, by setting a break point at the .logOut(...) line and stepping into that function. At some point it should do location.href = '...' so you should be able to see where that goes wrong.

Additionally, this gist might help with debugging too.

Let us know what you find out.

0reactions
jmelichcommented, Sep 12, 2019

The source code of the library has hardcoded the id_token, so that this attribute is essential to the whole logout flow. You just need to add an “id_token” to the localStorage/sessionStorage with nothing filled. Just add it and it should work fine.

Thanks for your almost instant reply. That was not exactly my case but made me realize which was my error, caused for a wrong config option.

Sorry and thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

IdentityServer4 and Angular: logout with Implicit flow
Everything seems to work fine, I can log in; and access token is available. If I click the logout button, I handle it...
Read more >
OAuth 2.0 implicit grant flow - The Microsoft identity platform
The implicit grant is only reliable for the initial, interactive portion of your sign-in flow, where the lack of third party cookies doesn't ......
Read more >
Configuring for Implicit Flow - angular-oauth2-oidc
This section shows how to implement login leveraging implicit flow. This is the OAuth2/OIDC flow which was originally intended for Single Page Application....
Read more >
Implicit flow authentication using angular-oauth2 ... - LinkedIn
In order to log out from the application, just need to call the logout() method of the OAuthService. It will end the session...
Read more >
OpenID Connect & OAuth 2.0 API - Okta Developer
If id_token or token is specified as the response type, then query isn't allowed as a response mode. Defaults to fragment in implicit...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found