Skip to content

Commit c671aa4

Browse files
committed
Disable ES512 in Safari: not supported for now.
1 parent 6887e94 commit c671aa4

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

src/dom-elements.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export const encodedTabLink =
1+
export const encodedTabLink =
22
document.querySelector('.tab-link a[href="#encoded-jwt"]');
3-
export const decodedTabLink =
3+
export const decodedTabLink =
44
document.querySelector('.tab-link a[href="#decoded-jwt"]');
55
export const encodedTabElement = document.getElementById('encoded-jwt');
66
export const decodedTabElement = document.getElementById('decoded-jwt');
@@ -15,17 +15,21 @@ export const signatureStatusElement =
1515
document.querySelector('.validation-status.js-signature');
1616

1717
export const algorithmSelect = document.getElementById('algorithm-select');
18+
export const algorithmEs512 =
19+
algorithmSelect.querySelector('option[value="ES512"]');
1820

19-
export const keyEditorContainer = document.querySelector('.jwt-signature pre.RS256');
21+
export const keyEditorContainer =
22+
document.querySelector('.jwt-signature pre.RS256');
2023
export const rsaShaTextSpan = document.getElementById('rsasha-text');
21-
export const secretEditorContainer = document.querySelector('.jwt-signature pre.HS256');
24+
export const secretEditorContainer =
25+
document.querySelector('.jwt-signature pre.HS256');
2226
export const hmacShaTextSpan = document.getElementById('hmacsha-text');
2327

2428
export const publicKeyTextArea =
2529
document.querySelector('.jwt-signature textarea[name="public-key"]');
2630
export const privateKeyTextArea =
2731
document.querySelector('.jwt-signature textarea[name="private-key"]');
28-
export const secretInput =
32+
export const secretInput =
2933
document.querySelector('.jwt-signature input[name="secret"]');
3034
export const secretBase64Checkbox =
3135
document.getElementById('is-base64-encoded');

src/editor/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
deferToNextLoop,
3-
safeLocalStorageSetItem,
4-
copyTokenLink
3+
safeLocalStorageSetItem
54
} from '../utils.js';
65
import { downloadPublicKeyIfPossible } from './public-key-download.js';
76
import { setupClaimsTooltip } from './claims-tooltip.js';
@@ -10,7 +9,8 @@ import {
109
getTrimmedValue,
1110
stringify,
1211
fixEditorHeight,
13-
getSelectedAlgorithm
12+
getSelectedAlgorithm,
13+
disableUnsupportedAlgorithms
1414
} from './utils.js';
1515
import { sign, verify, decode } from './jwt.js';
1616
import EventManager from './event-manager.js';
@@ -26,7 +26,6 @@ import {
2626
editorElement,
2727
headerElement,
2828
payloadElement,
29-
decodedElement,
3029
secretInput,
3130
privateKeyTextArea,
3231
publicKeyTextArea,
@@ -388,6 +387,7 @@ export function getTokenEditorValue() {
388387
}
389388

390389
export function setupTokenEditor() {
390+
disableUnsupportedAlgorithms();
391391
setupEvents();
392392
selectAlgorithm('HS256');
393393
loadToken();

src/editor/utils.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { tokenEditor } from './instances.js';
21
import { isWideScreen } from '../utils.js';
3-
import {
4-
algorithmSelect,
5-
publicKeyTextArea,
2+
import {
3+
algorithmSelect,
4+
algorithmEs512,
65
editorElement,
76
decodedElement
87
} from '../dom-elements.js';
@@ -32,3 +31,14 @@ export function getSelectedAlgorithm() {
3231
const selected = algorithmSelect.options[algorithmSelect.selectedIndex];
3332
return selected.value;
3433
}
34+
35+
export function isSafari() {
36+
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
37+
}
38+
39+
export function disableUnsupportedAlgorithms() {
40+
// TODO: test supported algorithms in runtime
41+
if(isSafari) {
42+
algorithmEs512.disabled = true;
43+
}
44+
}

0 commit comments

Comments
 (0)