Skip to content

Commit 0221d90

Browse files
committed
handle expires in correctly
1 parent 21670de commit 0221d90

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

projects/fusio-sdk/src/lib/service/fusio.service.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export abstract class FusioService<T extends ClientAbstract> {
6464
}
6565

6666
const unixTimestamp = Math.floor(Date.now() / 1000);
67-
return token.expires_in > unixTimestamp;
67+
return this.getExpiresInTimestamp(token.expires_in) > unixTimestamp;
6868
}
6969

7070
public logout(): void {
@@ -90,4 +90,16 @@ export abstract class FusioService<T extends ClientAbstract> {
9090
}
9191
}
9292

93+
private getExpiresInTimestamp(expiresIn: number): number
94+
{
95+
const nowTimestamp = Math.floor(Date.now() / 1000);
96+
97+
if (expiresIn < 529196400) {
98+
// in case the expires in is lower than 1986-10-09 we assume that the field represents the duration in seconds
99+
// otherwise it is probably a timestamp
100+
expiresIn = nowTimestamp + expiresIn;
101+
}
102+
103+
return expiresIn;
104+
}
93105
}

0 commit comments

Comments
 (0)