Closed fieldfoxWim closed 4 years ago
Ouch, cognito. That sucks.
I hope someone can help you but it's not me.
I solved it by creating my own refresh timers
aurelia.start().then(() => {
const auth = aurelia.container.get(AuthService);
const tokenRefreshTimer = 900; //seconds
if (auth.isAuthenticated()) {
if (auth.getTtl() <= tokenRefreshTimer) {
auth.updateToken().then(
() => {}).catch(console.error);
}
PLATFORM.global.setInterval(() => {
auth.updateToken().then(
() => {}
).catch(console.error);
}, tokenRefreshTimer*1000)
aurelia.setRoot('app')
} else {
aurelia.setRoot('login')
}
});
login() {
this.busy = true;
const self = this;
return this.authService.login({username: this.email, password:this.password, grant_type: "password"})
.then(() => {
PLATFORM.global.setInterval(() => {
this.authService.updateToken().then(
() => { }
).catch(console.error);
}, 60000)
this.aurelia.setRoot('app');
})
...
When I have time I might fork and do a pull request. Anyway If somebody wants to use Cognito - the above helps with the refreshtimers
Regards Wim
Ofcourse the setting autoUpdateToken
must be set to false
!
Hi All
Context I am using aurelia-authentication to authenticate with AWS Cognito. I have my own expressjs middleware in between. I have everything up and running and main functionality is doing well!
Special requirement I need to use Refreshtokens to keep users logged in. AWS Cognito requires that the access_token is still valid for at least 5min to be able to use the refresh token.
Solution 1 - partially working I use
setTimeout
to force an earlier invocation ofupdateToken()
, every 30 minutesProblem The timeout is only executed once, and when the automatic
updateToken()
kicks in it resets the timeout toTtl
of the access_token.Thanks anyway to share this great library!
Thank you Wim Devos