Skip to content

Commit d655980

Browse files
FrancescoMolinaroAdamF42
authored andcommitted
Merged in task/dspace-glam-2023_02_x/GLAM-1200 (pull request DSpace#3415)
[GLAM-1200] fix possible issue with expired token Approved-by: Andrea Barbasso Approved-by: Fapohunda, Adamo
2 parents d81b7ad + ede1eb4 commit d655980

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/mirador-viewer/config.default.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import Mirador from 'mirador/dist/es/src/index';
2+
import jwtDecode from "jwt-decode";
3+
24

35
// You can modify this default Mirador configuration file. However,
46
// you should consider creating a copy of this file named
@@ -85,7 +87,11 @@ windowSettings.manifestId = manifest;
8587
const authCookie = decodeURIComponent(value);
8688
const parsedCookie = JSON.parse(authCookie);
8789
if (parsedCookie && parsedCookie[tokenName]) {
88-
return `Bearer ${parsedCookie[tokenName]}`;
90+
const decodedJwt = jwtDecode(parsedCookie[tokenName]);
91+
const jwtExpDate = decodedJwt.exp * 1000;
92+
const isExpired = jwtExpDate <= Date.now();
93+
// if token is expired we don't use it as it would cause a 403
94+
return isExpired ? null : `Bearer ${parsedCookie[tokenName]}`;
8995
}
9096
}
9197
}

0 commit comments

Comments
 (0)