Hi, I am implementing the auto-login concept with the PKCE Code Flow. In my app.component.ts constructor I have the following:
if (this._oidcSecurityService.moduleSetup) {
this.doCallbackLogicIfRequired();
} else {
this._oidcSecurityService.onModuleSetup.subscribe(() => {
this.doCallbackLogicIfRequired();
});
}
In my ngOnInit I have the following:
ngOnInit(): void {
this._oidcSecurityService.getIsAuthorized().subscribe(auth => {
this.isAuthenticated = auth;
if (!this.isAuthenticated)
this._router.navigate(['/autologin']);
});
}
and in the method "doCallbackLogicIfRequired" i have:
private doCallbackLogicIfRequired(): void {
this._oidcSecurityService.authorizedCallbackWithCode(window.location.toString());
}
and in my auto-login.component.ts i have:
constructor(private _oidcSecurityService: OidcSecurityService) {
this.isAuthorizedSubscription = this._oidcSecurityService.onModuleSetup.subscribe(() => { this.onModuleSetup(); });
}
ngOnInit() {
if (this._oidcSecurityService.moduleSetup) {
this.onModuleSetup();
}
}
ngOnDestroy(): void {
this.isAuthorizedSubscription.unsubscribe();
}
private onModuleSetup() {
this._oidcSecurityService.authorize();
}
So my understanding and based on debugging the flow happens as follows:
So, now this is where I am having some issues and am not sure what is happening.
Here are the issues:
I am getting all strange issues with identity server after this is happening and I assume it is because of this _getIsAuthorized_ method.
Questions:
getIsAuthorized() subscription is supposed to be called? Do otherAny help would be appreciated, I am really struggling with this issue.
Thanks!
I suggest you follow the steps in the following article:
I had some issues with the auto-login flow too and these helped me find the problem.
It would be great to see an example of how this is supposed to work, especially as PKCE Code Flow is the recommended way to authenticate an angular app
@djkiwe it would be super awesome if you could share your solution. followed the steps above but... we want to switch from implicit(where this auto-login-flow is working) to pkce.. until now its just a--pain.
@bonaparte89 the solution for me was to change the "response_type" to "id_token token" and "trigger_authorization_result_event" to true
@bonaparte89 thanks. I will create an example when I get time, this has been due a long time... hope before the summer.
Sorry about this greetings Damien
This has been refactored and changed in verison 11 which we plan to release in the next few days after testing. Are Auto login example has been created and added to the samples
Greetings Damien
@damienbod I have some problem with auto login. The auto login works for the first time and the user is redirected to login page and back after login. But when the user logs out, getAuthorized is emitted and the user is sent back to auto login page and gets authorized. So, the log out doesn't work.
@damienbod facing the same issue . he auto login works for the first time and the user is redirected to login page and back after login. But when the user logs out, getAuthorized is emitted and the user is sent back to auto login page and gets authorized. So, the log out doesn't work.
The URL used for the redirect after the logout needs to be excluded from the auto login.
Can u explain little bit more because postLogoutRedirectUri: window.location.origin is the property that i am using .
I have two components namely header and naviagtion.
Inside header i have drop down where i have username and sign out anchor tag .
Inside naviagtion bar i have couple of links.
this is how app.component looks like.
header/header
navigation-bar
section class="container-fluid"
router-outle>/router-outlet
section
I have all these things in core module and core-routing module.
Now everytime i clicking signout , appcomponent is getting load and authentication mechanism is triggered.How can i prevent this.
