forked from jsonwebtoken/jsonwebtoken.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
102 lines (86 loc) · 2.35 KB
/
Copy pathutils.js
File metadata and controls
102 lines (86 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//import { KEYUTIL } from 'jsrsasign';
import log from 'loglevel';
import clipboard from 'clipboard-polyfill';
export function httpGet(url, cache = true) {
return new Promise((resolve, reject) => {
const request = new XMLHttpRequest();
request.onreadystatechange = () => {
if (request.readyState === XMLHttpRequest.DONE) {
if (request.status === 200) {
resolve(request.responseText);
} else {
reject({
status: request.status,
response: request.responseText
});
}
}
};
request.open('GET', url);
if (!cache) {
request.setRequestHeader("Cache-Control", "no-cache");
}
request.send();
});
}
/*export function isValidKey(key) {
// Four tries: no header, header for cert, header for pub key,
// header for priv key
const headers = [{
prologue: '',
epilogue: ''
},{
prologue: '-----BEGIN CERTIFICATE-----\n',
epilogue: '-----END CERTIFICATE-----\n'
}, {
prologue: '-----BEGIN PUBLIC KEY-----\n',
epilogue: '-----END PUBLIC KEY-----\n'
}, {
prologue: '-----BEGIN PRIVATE KEY-----\n',
epilogue: '-----END PRIVATE KEY-----\n'
}, {
prologue: '-----BEGIN RSA PRIVATE KEY-----\n',
epilogue: '-----END RSA PRIVATE KEY-----\n'
}];
for(let i = 0; i < headers.length; ++i) {
const header = headers[i];
try {
let newKey = header.prologue;
newKey += key + '\n';
newKey += header.epilogue;
return {
valid: !!KEYUTIL.getKey(newKey),
key: newKey
};
} catch(e2) {
// Ignore
}
}
return {
valid: false,
key: key
};
}*/
export function deferToNextLoop(func) {
setTimeout(func, 1);
}
export function copyTokenLink(token, publicKeyOptional) {
let url = `https://jwt.io/#debugger-io?token=${encodeURIComponent(token)}`;
if(publicKeyOptional) {
url += `&publicKey=${encodeURIComponent(publicKeyOptional)}`;
}
clipboard.writeText(url);
return url;
}
export function isWideScreen() {
return window.matchMedia('(min-width: 768px)').matches;
}
export function safeLocalStorageSetItem(key, value) {
try {
localStorage.setItem(key, value);
} catch (e) {
log.info('Cannot save token to Local Storage ' +
'(private browsing enabled?), ignoring...', e);
// Safari when in private browsing doesn't allow it
}
}