Skip to content

Recommended way of oauth2 guarding entire application. #478

Closed
@ronnyek

Description

@ronnyek

Greetings.
I've used this library in a number of angular applications before, but I must be doing something wrong, and am hoping I can get to the bottom of this stuff.

Basically I've got applications I'd like to initialize where it'll check for token in whatever storage, and redirect to login immediately.

Currently I've done things like this:

    this.oauthService.configure(this.securityConfig.oidcConfig);
    this.oauthService.tokenValidationHandler = new JwksValidationHandler();

   console.log('attempting to login');
   this.oauthService.loadDiscoveryDocumentAndTryLogin({
        onLoginError: (params: any) => {
          console.log('Error logging in', params);
        },
        onTokenReceived: (receivedTokens: any) => {
          console.log('Logged in, received tokens: ', receivedTokens);
        }}).catch(
        (err: any) => {
          console.log('could not load discovery doc: ', err);
        });

    });

Very frequently I'll end up at a page that just doesn't login, end up with a white screen and console log that says 'attempting to login'. My Identity server reports no errors, but just never goes further than that.

So I guess my question is, if I decide to not have a explicit login/logout button that calls initImplicitFlow(), how do I best fire my app up in such a way that I redirect immediately if no VALID token has been stored?

I tried checking after that loadDiscoveryDocAndTryLogin for a token, and then calling initImplicitFlow(), which seems to help in some cases, and in other, it causes just constant redirects to identity server and then back.

Metadata

Metadata

Assignees

No one assigned

    Labels

    more-info-neededPlease provide a minimal example (e.g. at stackblitz.com) which demonstrates the issue

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions