In my component I have a property bound to the isAuthorized which remains false since authorizedCallback is async.
ngOnInit() {
if (window.location.hash) {
this.oidcSecurityService.authorizedCallback();
}
this.authenticated = this.oidcSecurityService.isAuthorized;
}
The way I got around this is by subscribing to the onUserDataLoaded EventEmitter, but it feels like there should be an Observable that can emit specifically for this property.
If your using the main component, you need to wait for an event.
you could wait for the onUserDataLoaded event.
this.oidcSecurityService.onUserDataLoaded.subscribe(() => { this.onUserDataLoaded(); });
And Implement a separate function and set your authenticated property.
Or if you use the this.oidcSecurityService.isAuthorized directly in the template, it will be updated when it is set.
@robisim74 @FabianGosebrink Do we need a new event for the isAuthorized?
The authorizedCallback method already emits the event that you have indicated: https://github.com/damienbod/angular-auth-oidc-client/blob/master/src/services/oidc.security.service.ts#L239
This event is emitted after that isAuthorized is set: https://github.com/damienbod/angular-auth-oidc-client/blob/master/src/services/oidc.security.service.ts#L229
So the following code in my opinion is correct:
ngOnInit() {
if (typeof location !== "undefined" &&window.location.hash) {
this.oidcSecurityService.authorizedCallback();
this.oidcSecurityService.onUserDataLoaded.subscribe(() => {
this.authenticated = this.oidcSecurityService.isAuthorized;
});
}
}
I think that another event is useless. Perhaps a more explanation of this event is needed in the docs.
fixing here
https://github.com/damienbod/angular-auth-oidc-client/issues/42
The onUserDataLoaded is only emitted after a login from a id_token token flow. This does not work with a id_token flow (which is anyway useless but has to be supported for OIDC certification) and also with a browser refresh
Updated 1.3.0
Most helpful comment
The
authorizedCallbackmethod already emits the event that you have indicated: https://github.com/damienbod/angular-auth-oidc-client/blob/master/src/services/oidc.security.service.ts#L239This event is emitted after that
isAuthorizedis set: https://github.com/damienbod/angular-auth-oidc-client/blob/master/src/services/oidc.security.service.ts#L229So the following code in my opinion is correct:
I think that another event is useless. Perhaps a more explanation of this event is needed in the docs.