OidcSecurityService.getIsAuthorized() return false after Hot Module Reload
See original GitHub issueSince 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:
- Created 5 years ago
- Comments:12 (7 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 😃
You may want to wait to check getIsAuthorized() until after setup is complete. It defaults to false.
So something like: