I followed readme.md to setup my app, and it woks until token returns. It can't parse token and try login over and over again.
I found after loading document, the window.location.hash is disappear. so tryLogin is fail. please tell me How can I do ? Thank you.
private configureWithNewConfigApi() {
this.oauthService.configure(authConfig);
this.oauthService.tokenValidationHandler = new JwksValidationHandler();
console.log('configureWithNewConfigApi', window.location);
this.oauthService.loadDiscoveryDocument().then((doc) => {
console.log('loadDiscoveryDocument', window.location);
this.oauthService.tryLogin({
onTokenReceived: context => {
console.log('onTokenReceived:', context);
this.authService.init();
},
onLoginError: (err) => {
console.log('onLoginError:', err);
}
}).then(() => {
if (!this.oauthService.hasValidIdToken() || !this.oauthService.hasValidAccessToken()) {
this.oauthService.initImplicitFlow();
}
});
});
}
I am facing the same error here guys.
It is related to this issue.
Angular router actually strips out the query string params and when the oauthService got instantiated is too late to retrieve the token.
Possible strategies could be:
@manfredsteyer any advices on this topic?
@AndreaPaciolla
Here is my current solution.
const hash = window.location.hash;
this.oauthService.loadDiscoveryDocument().then((doc) => {
this.oauthService.tryLogin({
customHashFragment: hash,
onTokenReceived: context => {
this.oauthService.loadUserProfile().then((userInfo) => {
this.init((<UserInfo>userInfo));
this.router.navigate(['/']);
});
},
onLoginError: (err) => {
this.logger.log('onLoginError:', err);
}
}).then(() => {
if (!this.oauthService.hasValidIdToken() || !this.oauthService.hasValidAccessToken()) {
this.oauthService.initImplicitFlow();
}
});
});
Yes @alonstar for now that seems to be the way. Thank you
Thx for this. I think turning off initial routing, like shown here [1] should also do the job.
Perhaps adding a catch all route (path: '**') at the end of the AppModule's routing table also helps.
Btw: There is a new convenince method that does almost what your method does. It's called loadDiscoveryDocumentAndLogin (not to be confused with loadDiscoveryDocumentAndTryLogin). See also my comment in #179 for this.
Thanks for your suggestions @manfredsteyer.
Just a clarification about:
Perhaps adding a catch all route (path: '**') at the end of the AppModule's routing table also helps.
That could be the case when ** is not already used for another component (_e.g. 404 component, as in my context_).
Most helpful comment
@AndreaPaciolla
Here is my current solution.