Skip to content

Commit 79d16b1

Browse files
added api key labels
1 parent 60c2a75 commit 79d16b1

4 files changed

Lines changed: 28 additions & 14 deletions

File tree

Assets/css/profile.css

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,13 @@ th {
338338
overflow: hidden;
339339
}
340340

341-
.apiKeysTable td:nth-child(2) {
341+
.apiKeysTable td:nth-child(4) {
342342
display: flex;
343-
gap: 1em;
343+
gap: .5em;
344344
}
345345

346-
.apiKeysTable td:nth-child(2) button {
347-
padding: .8em;
346+
.apiKeysTable td:nth-child(4) button {
347+
padding: .5em;
348348
}
349349

350350
.apiKeysTable td {
@@ -439,6 +439,7 @@ th {
439439

440440
.thirdPartyApps-container > div > button {
441441
margin-left: auto;
442+
padding: .5em 2em;
442443
}
443444

444445
.thirdPartyApps-container > div > h1 {
@@ -476,6 +477,14 @@ a {
476477
margin-bottom: 1em;
477478
}
478479

480+
.passkeys > div h1 {
481+
font-size: 1.5em;
482+
}
483+
484+
.passkeys > div p {
485+
font-size: 0.9em;
486+
}
487+
479488
.passkeys > div h1, .passkeys > div p {
480489
margin: 0;
481490
}
@@ -592,12 +601,12 @@ a {
592601
font-size: 0.85em;
593602
}
594603

595-
.apiKeysTable td:nth-child(2) {
604+
.apiKeysTable td:nth-child(4) {
596605
flex-direction: column;
597606
gap: .5em;
598607
}
599608

600-
.apiKeysTable td:nth-child(2) button {
609+
.apiKeysTable td:nth-child(4) button {
601610
padding: .5em;
602611
width: 100%;
603612
}

Assets/js/data/auth/createApiKey.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
export async function createApiKey(scope) {
1+
export async function createApiKey(label, scope) {
22
await LoginManager.validateToken();
33
const req = await fetch(`https://api.login.${LoginManager.domain}/user/apikey`, {
44
method: 'POST',
55
headers: {
66
Authorization: `Bearer ${LoginManager.getCookie('token')}`,
77
'Content-Type': 'application/json',
88
},
9-
body: `"${scope}"`,
9+
body: JSON.stringify({ label, scope }),
1010
});
1111

1212
if (req.status === 401) {

Assets/js/profile.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ LoginManager.isLoggedIn().then(async (e) => {
120120
'2faType': 'App',
121121
api_keys: [
122122
{
123+
label: 'Test API Key',
123124
clientId: '1234567890',
124125
scope: 'admin',
125126
},
@@ -251,7 +252,7 @@ LoginManager.isLoggedIn().then(async (e) => {
251252
});
252253

253254
currentUser.api_keys.forEach((key) => {
254-
document.getElementById('apiKeysTable').appendChild(createApiKeyRow(key.clientId, key.scope));
255+
document.getElementById('apiKeysTable').appendChild(createApiKeyRow(key.label, key.clientId, key.scope));
255256
});
256257

257258
if (currentUser.trusted_sso_clients.length > 0) document.getElementById('thirdPartyAppsContainer').innerHTML = '';
@@ -639,10 +640,10 @@ async function doubleClickButton(e, func) {
639640
}, 3000);
640641
}
641642

642-
function createApiKeyRow(client_id, scope) {
643+
function createApiKeyRow(label, client_id, scope) {
643644
const row = document.createElement('tr');
644645
row.id = client_id;
645-
row.innerHTML = `<td>${client_id}</td><td>${scope}</td>`;
646+
row.innerHTML = `<td>${label}</td><td>${client_id}</td><td>${scope}</td>`;
646647
const td = document.createElement('td');
647648
const deleteBtn = document.createElement('button');
648649
const regenBtn = document.createElement('button');
@@ -660,6 +661,7 @@ function createApiKeyRow(client_id, scope) {
660661
}
661662

662663
async function createApiKey() {
664+
document.getElementById('label').value = '';
663665
document.getElementById('scope').value = '';
664666
document.getElementById('apiKeyDialog').show();
665667

@@ -680,9 +682,10 @@ async function createApiKey() {
680682

681683
if (!dialogRes) return false;
682684

685+
const label = document.getElementById('label').value;
683686
const scope = document.getElementById('scope').value;
684687

685-
if (scope.length === 0) {
688+
if (label.length === 0 || scope.length === 0) {
686689
createDialog('Error', 'Please fill out all fields!', 'error');
687690
return;
688691
}
@@ -705,7 +708,7 @@ async function createApiKey() {
705708
}
706709
}
707710

708-
const req = await createApiKeyReq(scope);
711+
const req = await createApiKeyReq(label, scope);
709712
const res = await req.json();
710713

711714
if (res.statusCode !== 203) {
@@ -714,7 +717,7 @@ async function createApiKey() {
714717
return;
715718
}
716719

717-
document.getElementById('apiKeysTable').appendChild(createApiKeyRow(res.data.clientId, res.data.scope));
720+
document.getElementById('apiKeysTable').appendChild(createApiKeyRow(res.data.label, res.data.clientId, res.data.scope));
718721

719722
createDialog('Success', `Successfully created API key! Please save it now, as it will not be shown again! ${res.data.clientSecret}`, 'info');
720723
}

profile/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ <h1>Api Keys</h1>
266266

267267
<table id="apiKeysTable" class="apiKeysTable">
268268
<tr>
269+
<th>Label</th>
269270
<th>Key</th>
270271
<th>Scope</th>
271272
<th>Actions</th>
@@ -360,6 +361,7 @@ <h1>Danger Zone</h1>
360361
<button target-dialog target="createSSODialog" style="display: none;"></button>
361362
<button target-dialog target="apiKeyDialog" style="display: none;"></button>
362363
<div id="apiKeyDialog" class="custom-dialog">
364+
<input id="label" placeholder="Label" type="text">
363365
<input id="scope" placeholder="Scope" type="text">
364366

365367
<div class="flex end">

0 commit comments

Comments
 (0)