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.

OidcSecurityService.getIsAuthorized() return false after Hot Module Reload

See original GitHub issue

Since version 6.0.9, when webpack updates modified modules, the value returned by OidcSecurityService.getIsAuthorized() is false while the token is valid.

Before 6.0.9 everything worked well.

The problem is located during AuthGuard.canActivate() method :

public canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
        return this.oidcSecurityService.getIsAuthorized()
            .pipe(
                switchMap((isAuthorized: boolean) => {
                    console.log('From [AuthGuard.canActivate] (getIsAuthorized)', isAuthorized);
                    if (isAuthorized) {
                        ...
                    }
                    ...
                    this.router.navigate(['/auth/signin']);
                    ...
                })
            );
    }

Because isAuthorized is always false the user is redirected to /auth/signin page. Here are the debug logs :

From [AuthGuard.canActivate] (getIsAuthorized) false
Information: Connection disconnected.
onUserDataChanged: last = undefined, new = 
onUserDataChanged: last = , new = [object Object]
IsAuthorized setup module
eyJhbGciOiJSUzI1NiIsImtpZCI6IkQwRUI5MzkzNDUwN0JGRTVENzcyNEUyQTY4ODFGREYxMzNGQzdDMDAiLCJ0eXAiOiJKV1QiLCJ4NXQiOiIwT3VUazBVSHYtWFhjazRxYUlIOThUUDhmQUEifQ.eyJuYmYiOjE1Mzg1NTAxMDgsImV4cCI6MTUzODYzNjUwOCwiaXNzIjoiaHR0cHM6Ly9sb2NhbGhvc3QvaWRlbnRpdHkiLCJhdWQiOiJwYXRjaHdvcmsiLCJub25jZSI6Ik4wLjY0ODE2NjQ0NjAzMjE3NTcxNTM4NTUwMTA4NDY4IiwiaWF0IjoxNTM4NTUwMTA4LCJhdF9oYXNoIjoiajh6elhGTlJhVnZqdGVOaTA5SkxWdyIsInNpZCI6ImU2YzRkMTY0NThjMTEzYzE1NWQ3NjY2Mzc2MmUzNWRmIiwic3ViIjoiNWI3NGU2YzRlZGQwYmYwMzY4Njg2NTJmIiwiYXV0aF90aW1lIjoxNTM4NTQzNjIyLCJpZHAiOiJsb2NhbCIsImFtciI6WyJwd2QiXX0.mWWX-0nuWBjG_2RI5_APcH1p-TdL1Dn3hK7dwvfuOlOnbdEy4bTcvJzwHENTC8DPJUzQyCyKmvRXqpgZdu2AsLumRwxR83zLucFbOKnIvygMqCYC3_DhUmDZheytN8DcYoUBgXYzDFnozPeVyAcokLH5pVpAi9wKKGe5Ta7yt-pbYjMndWMRbFstQcrQ6PF0DtHt-EH9BLtIMza6TIe8m51sS2syYy1lRjpvZ77t3kA-FZ_PSz64V_c6cmq_oD4cxMhyUTNYszU2SwZLFmZCcYYPaSXkaO4HHxCLnhoZniwkf_PzHl6Z9v6uPWuaCCslYviLjyqzCFz3Zfnzh5t_nA
IsAuthorized setup module; id_token is valid
STS server: https://localhost/identity
onUserDataChanged: last = [object Object], new = 
onUserDataChanged: Logout detected.
BEGIN Authorize, no auth data
AuthorizedController created. local state: 15385501344780.47234499238051386

Once again, until the version 6.0.9 everything worked well. I looked at the code here but I didn’t find something relevant.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
cveronscommented, Oct 3, 2018

Thank you @profet23, this was the problem indeed.

Do you think this can be part of getIsAuthorized() method to wait after setup is complete ? Or at least update the doc https://github.com/damienbod/angular-auth-oidc-client#using-guards ?

Anyway thanks again, great job guys 😃

3reactions
profet23commented, Oct 3, 2018

You may want to wait to check getIsAuthorized() until after setup is complete. It defaults to false.

So something like:

        return new Observable<boolean>((subscriber) => {
            if (this.oidcSecurityService.moduleSetup) {
                subscriber.next(true);
                subscriber.complete();
            }
            else {
                this.oidcSecurityService.onModuleSetup.pipe(take(1)).subscribe(() => {
                    subscriber.next(true);
                    subscriber.complete();
                });
            }
        })
        .pipe(
            switchMapTo(this.oidcSecurityService.getIsAuthorized()),
            map((isAuthorized: boolean) => {
                console.log('AuthorizationGuard, canActivate isAuthorized: ' + isAuthorized);
                if (isAuthorized) {
                    return true;
                }
                this.router.navigate(['/unauthorized']);
                return false;
            }),
            take(1)
        )
Read more comments on GitHub >

github_iconTop Results From Across the Web

Stuck in redirect loop with identity server using the code ...
The main issue is that when I hit the request asking for the token in angular-auth-oidc-client.js (code below), the requests keeps flipping back...
Read more >
angular-auth-oidc-client/README.md - UNPKG
The `OidcSecurityService` has a dependency on the `HttpClientModule` which needs to be imported. The angular-auth-oidc-client module supports all versions of ...
Read more >
OpenID Connect with Angular 8 (OIDC Part 7)
This is using code flow grant type and will validate the requesters code_verifier and authorization code before returning the requested tokens. As usual,...
Read more >
Angular OpenID Connect Implicit Flow with IdentityServer4
Enables Hot Module Replacement. ... iss_validation_off: false ... IsAuthorized() which is set using the OidcSecurityService authorize ...
Read more >
angular-auth-oidc-client - npm
Import the module and services in your module. The OidcSecurityService has a dependency on the HttpClientModule which needs to be imported.
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