manfredsteyer / angular2-oauth2

63 stars 49 forks source link

Init implicit flow on page load #36

Open svrooij opened 7 years ago

svrooij commented 7 years ago

I'm trying to implement some sort of single-sign-on when the user loads the app but doesn't have a valid (access-/)identitytoken. How who we implement this?

  1. User enters page
  2. Not logged in?
  3. Redirect to token provider
  4. Check the token
  5. Access the application

We want to implement it so the user doesn't have to press the login button, they are probably already logged-in so they'll get a token instantly.

Where should I put the initImplicitFlow() call for this to happen?

stumpyfr commented 7 years ago

Working solution for me, in your app component when you initialize the service:

    this.oauthService.loadDiscoveryDocument().then(() => {
      this.oauthService.tryLogin({});
      if (this.oauthService.getIdToken() == null) {
        this.oauthService.initImplicitFlow();
      }
    });
    this.oauthService.tryLogin({});
svrooij commented 7 years ago

That works perfectly, but it looks wrong.

stumpyfr commented 7 years ago

I agree at 100%, as always with oAuth/openID, a lot of magic :)