Skip to content

Commit d742b5a

Browse files
authored
Merge pull request #3 from geoblocks/fix_leeway
Fix leeway
2 parents d6375f3 + e40d824 commit d742b5a

File tree

3 files changed

+50
-47
lines changed

3 files changed

+50
-47
lines changed

package-lock.json

Lines changed: 42 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@geoblocks/oidcjs",
3-
"version": "0.5.9",
3+
"version": "0.5.10",
44
"description": "A simple OpenID Connect client typescript implementation",
55
"scripts": {
66
"start": "python3 -m http.server 8000 --bind localhost",
@@ -16,7 +16,7 @@
1616
"main": "lib/index.js",
1717
"types": "lib/types/index.d.ts",
1818
"devDependencies": {
19-
"@biomejs/biome": "1.7.0",
20-
"typescript": "5.4.5"
19+
"@biomejs/biome": "1.8.2",
20+
"typescript": "5.5.2"
2121
}
2222
}

src/code.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,11 @@ export class CodeOIDCClient {
324324
if (!payload) {
325325
return false;
326326
}
327-
// Add 30 seconds to the expiration time to account for clock skew
328-
return payload.exp + 30 > Date.now() / 1000;
327+
// Substract 30 seconds to the token expiration time
328+
// to eagerly renew the token and give us some margin.
329+
// This is necessary to account of clock discrepency between client and server.
330+
// Ideally, the server also tolerate some leeway.
331+
return payload.exp - 30 > Date.now() / 1000;
329332
}
330333

331334
async getActiveToken(): Promise<string> {

0 commit comments

Comments
 (0)