From 0f4cff5e593192ca76b8258eae9919f4c6c640f6 Mon Sep 17 00:00:00 2001
From: zachmann <gabriel.zachmann@kit.edu>
Date: Tue, 27 Feb 2024 08:49:03 +0100
Subject: [PATCH] [web] improve JWT badge in tokeninfo pane

---
 CHANGELOG.md                                      | 6 ++++++
 internal/server/web/partials/tokeninfo.mustache   | 3 +++
 internal/server/web/static/js/tokeninfo-status.js | 6 ++++++
 3 files changed, 15 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2a952dda..315d83dd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,12 @@
 <!-- ### Dependencies -->
 <!--  -->
 
+## mytoken 0.10.0
+
+### Enhancements
+
+- In the tokeninfo pane in the webinterface expires JWTs now get a more precise badge.
+
 ## mytoken 0.9.1
 
 ### Enhancements
diff --git a/internal/server/web/partials/tokeninfo.mustache b/internal/server/web/partials/tokeninfo.mustache
index db8336b0..4825440a 100644
--- a/internal/server/web/partials/tokeninfo.mustache
+++ b/internal/server/web/partials/tokeninfo.mustache
@@ -13,6 +13,9 @@
                 <span class="ml-2 badge badge-pill badge-danger tokeninfo-token-type d-none"
                       id="tokeninfo-token-type-JWT-invalid"
                       data-toggle="tooltip" data-placement="top" title="Signature invalid">JWT</span>
+                <span class="ml-2 badge badge-pill badge-warning tokeninfo-token-type d-none"
+                      id="tokeninfo-token-type-JWT-exp"
+                      data-toggle="tooltip" data-placement="top" title="Signature valid, token expired">JWT</span>
 
                 <span class="ml-2 badge badge-pill badge-success" id="tokeninfo-token-valid"
                       data-toggle="tooltip" data-placement="top" title="Mytoken is valid and can be used">
diff --git a/internal/server/web/static/js/tokeninfo-status.js b/internal/server/web/static/js/tokeninfo-status.js
index 16f86f4b..a8dcc9b0 100644
--- a/internal/server/web/static/js/tokeninfo-status.js
+++ b/internal/server/web/static/js/tokeninfo-status.js
@@ -4,6 +4,7 @@ const $tokeninfoBadgeName = $('#tokeninfo-token-name');
 const $tokeninfoBadgeTypeShort = $('#tokeninfo-token-type-short');
 const $tokeninfoBadgeTypeJWTValid = $('#tokeninfo-token-type-JWT-valid');
 const $tokeninfoBadgeTypeJWTInvalid = $('#tokeninfo-token-type-JWT-invalid');
+const $tokeninfoBadgeTypeJWTExpired = $('#tokeninfo-token-type-JWT-exp');
 const $tokeninfoBadgeValid = $('#tokeninfo-token-valid');
 const $tokeninfoBadgeInvalid = $('#tokeninfo-token-invalid');
 const $tokeninfoBadgeMytokenIss = $('#tokeninfo-token-mytoken-iss');
@@ -54,6 +55,7 @@ async function update_tokeninfo() {
         let mytokenIss = payload['iss'];
         $tokeninfoTypeBadges.hideB();
         $tokeninfoBadgeTypeJWTInvalid.showB();
+        $tokeninfoBadgeTypeJWTExpired.hideB();
         if (mytokenIss.endsWith("/")) {
             mytokenIss = mytokenIss.substring(0, mytokenIss.length - 1);
         }
@@ -80,6 +82,10 @@ async function update_tokeninfo() {
             if (e instanceof jose.errors.JWTInvalid) {
                 $tokeninfoTypeBadges.hideB();
                 $tokeninfoBadgeTypeShort.showB();
+            }
+            if (e instanceof jose.errors.JWTExpired) {
+                $tokeninfoBadgeTypeJWTInvalid.hideB();
+                $tokeninfoBadgeTypeJWTExpired.showB();
             } else {
                 console.error(e);
             }
-- 
GitLab