|
@@ -1,7 +1,8 @@
|
1
|
1
|
// @flow
|
2
|
2
|
|
3
|
3
|
import { Client } from '@microsoft/microsoft-graph-client';
|
4
|
|
-import rs from 'jsrsasign';
|
|
4
|
+import base64js from 'base64-js';
|
|
5
|
+
|
5
|
6
|
import type { Dispatch } from 'redux';
|
6
|
7
|
|
7
|
8
|
import { createDeferred } from '../../../../modules/util/helpers';
|
|
@@ -452,8 +453,13 @@ function getValidatedTokenParts(tokenInfo, guids, appId) {
|
452
|
453
|
return null;
|
453
|
454
|
}
|
454
|
455
|
|
455
|
|
- const payload
|
456
|
|
- = rs.KJUR.jws.JWS.readSafeJSONString(rs.b64utoutf8(tokenParts[1]));
|
|
456
|
+ let payload;
|
|
457
|
+
|
|
458
|
+ try {
|
|
459
|
+ payload = JSON.parse(b64utoutf8(tokenParts[1]));
|
|
460
|
+ } catch (e) {
|
|
461
|
+ return null;
|
|
462
|
+ }
|
457
|
463
|
|
458
|
464
|
if (payload.nonce !== guids.authNonce
|
459
|
465
|
|| payload.aud !== appId
|
|
@@ -596,3 +602,40 @@ function s4(num) {
|
596
|
602
|
|
597
|
603
|
return ret;
|
598
|
604
|
}
|
|
605
|
+
|
|
606
|
+/**
|
|
607
|
+ * Convert a Base64URL encoded string to a UTF-8 encoded string including CJK or Latin.
|
|
608
|
+ *
|
|
609
|
+ * @param {string} str - The string that needs conversion.
|
|
610
|
+ * @private
|
|
611
|
+ * @returns {string} - The converted string.
|
|
612
|
+ */
|
|
613
|
+function b64utoutf8(str) {
|
|
614
|
+ let s = str;
|
|
615
|
+
|
|
616
|
+ // Convert from Base64URL to Base64.
|
|
617
|
+
|
|
618
|
+ if (s.length % 4 === 2) {
|
|
619
|
+ s += '==';
|
|
620
|
+ } else if (s.length % 4 === 3) {
|
|
621
|
+ s += '=';
|
|
622
|
+ }
|
|
623
|
+
|
|
624
|
+ s = s.replace(/-/g, '+').replace(/_/g, '/');
|
|
625
|
+
|
|
626
|
+ // Convert Base64 to a byte array.
|
|
627
|
+
|
|
628
|
+ const bytes = base64js.toByteArray(s);
|
|
629
|
+
|
|
630
|
+ // Convert bytes to hex.
|
|
631
|
+
|
|
632
|
+ s = bytes.reduce((str_, byte) => str_ + byte.toString(16).padStart(2, '0'), '');
|
|
633
|
+
|
|
634
|
+ // Convert a hexadecimal string to a URLComponent string
|
|
635
|
+
|
|
636
|
+ s = s.replace(/(..)/g, '%$1');
|
|
637
|
+
|
|
638
|
+ // Decodee the URI component
|
|
639
|
+
|
|
640
|
+ return decodeURIComponent(s);
|
|
641
|
+}
|