-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtokenhandler.html
116 lines (105 loc) · 4.16 KB
/
tokenhandler.html
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html>
<head>
<title>VISS Web Client - Tokens</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="images/favicon.ico">
<link rel="stylesheet" href="styles/menu.css" type="text/css">
<link rel="stylesheet" href="styles/general.css" type="text/css">
<script src = "scripts/js/logger.js"></script>
<script src = "scripts/js/encoding.js"></script>
<script src = "scripts/js/tokenhandler.js"> </script>
</head>
<body>
<script src = "scripts/js/menu.js"></script>
<h2>Token Management</h2>
<h3>Access Grant Tokens</h3>
<div id="agts" class="token_container">
</div>
<h3 style="float: none;">Access Tokens</h3>
<div id="ats" class="token_container">
</div>
<script>
// Print the access grant tokens stored in indexed db in the html page
var atList;
var agtList;
printAGTs();
async function printAGTs(){
document.getElementById("agts").innerHTML = "";
agtList = await getAgtList();
for (var i = 0; i < agtList.length; i++) {
var agt = agtList[i];
var agtDiv = '<div id="agt' + agt.tokenId + '" class="token_box">'
+ '<p class = "subject">' + 'ID: ' + agt.tokenId
+ '<button onclick="copyToClipboard(\'agt' + agt.tokenId + '\')">Copy</button>'
+ '<button onclick="buttonDeleteAgt(\'agt'+agt.tokenId + '\')">Delete</button></p>'
+ '<h5>Header</h5>'
+ '<pre class = "data">' + JSON.stringify(agt.header, null, 4) + '</pre>'
+ '<h5>Payload</h5>'
+ '<pre class = "data">' + JSON.stringify(agt.payload, null, 4) + '</pre>'
+ '<p class = "details">'
+ 'Associated Key: ' + agt.keyAssociated + '<br>'
+ (agt.payload.exp < Date.now()/1000 ?
'<span class = "red"> Expired </span>' :
'<span class ="green"> Expires: ' + new Date(agt.payload.exp*1000).toLocaleString() + "</span>")
+ '</p>'
+'</div>';
document.getElementById("agts").insertAdjacentHTML('beforeend', agtDiv);
}
}
// Print the access tokens stored in indexed db in the html page
printATs();
async function printATs(){
document.getElementById("ats").innerHTML = "";
atList = await getAtList();
for (var i = 0; i < atList.length; i++) {
var at = atList[i];
var atDiv = '<div id="at' + at.tokenId + '" class="token_box"">'
+ '<p class = "subject"> ID: ' + at.tokenId
+ '<button onclick="copyToClipboard(\'at'+at.tokenId + '\')">Copy</button>'
+ '<button onclick="buttonDeleteAt(\'at'+at.tokenId+'\')">Delete</button>'
+ '</p>'
+ '<h5>Header</h5>'
+ '<pre class = "data">' + JSON.stringify(at.header, null, 4) + '</pre>'
+ '<h5>Payload</h5>'
+ '<pre class = "data">' + JSON.stringify(at.payload, null, 4) + '</pre>'
+ '<p class = "details">'
+ (at.payload.exp < Date.now()/1000 ?
'<span class = "red"> Expired </span>' :
'<span class ="green"> Expires: ' + new Date(at.payload.exp*1000).toLocaleString() + "</span>")
+ '</p>'
+'</div>';
document.getElementById("ats").insertAdjacentHTML('beforeend', atDiv);
}
}
// Dynamically delete Access Grant Token with the given id
function buttonDeleteAgt(id){
console.log(id);
deleteAgt(id.replace("agt", ""));
document.getElementById(id).remove();
}
// Dynamically delete Access Token with given id
function buttonDeleteAt(id){
deleteAt(id.replace("at", ""));
document.getElementById(id).remove();
}
// Copies the token to the clipboard
function copyToClipboard(id){
let copyTextToClipboard = "";
if (id.startsWith("agt")){
agt = agtList.find(agt => agt.tokenId == id.replace("agt", ""));
if (agt.tokenId == id.replace("agt", "")){
copyTextToClipboard = agt.encoded;
}
} else if (id.startsWith("at")){
at = atList.find(at => at.tokenId == id.replace("at", ""));
if (at.tokenId == id.replace("at", "")){
copyTextToClipboard = at.encoded;
}
}
navigator.clipboard.writeText(copyTextToClipboard);
}
</script>
</body>
</html>