From ce252a6aa052e8fcb161797a556f51c78f616fc7 Mon Sep 17 00:00:00 2001
From: wangrong <wangrong@shsening.com>
Date: 星期三, 22 十二月 2021 15:34:55 +0800
Subject: [PATCH] add jwt base64code fuction

---
 js/index.js |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/js/index.js b/js/index.js
index 1633744..18f48d4 100644
--- a/js/index.js
+++ b/js/index.js
@@ -24,7 +24,7 @@
     var jwt_header_ = new buffer.Buffer(strs_[0].toString('base64'), 'base64').toString();
     var jwt_payload_ = new buffer.Buffer(strs_[1].toString('base64'), 'base64').toString();
     var hash = CryptoJS.HmacSHA256(strs_[0] + '.' + strs_[1], "sxyd");
-    var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);
+    var hashInBase64 = base64UrlEncode(hash);
     var reg = RegExp(strs_[2]);
     if (!reg.exec(hashInBase64)) {
       // verification failed, go back
@@ -261,3 +261,10 @@
   mars3d.widget.disableAll();
   map.flyHome();
 }
+
+function base64UrlEncode(str) {
+  var encodedSource = CryptoJS.enc.Base64.stringify(str);
+  var reg = new RegExp('/', 'g');
+  encodedSource = encodedSource.replace(/=+$/,'').replace(/\+/g,'-').replace(reg,'_');
+  return encodedSource;
+}
\ No newline at end of file

--
Gitblit v1.9.1