Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: management of API tokens via ACP
- Loading branch information
Showing
11 changed files
with
135 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"tokens": "Tokens", | ||
"lead-text": "From this page you can configure access to the Write API in NodeBB.", | ||
"intro": "By default, the Write API authenticates users based on their session cookie, but NodeBB also supports Bearer authentication via tokens generated via this page.", | ||
"docs": "Click here to access the full API specification", | ||
|
||
"uid": "User ID", | ||
"uid-help-text": "Specify a User ID to associate with this token. If the user ID is <code>0</code>, it will be considered a <em>master</em> token, which can assume the identity of other users based on the <code>_uid</code> parameter", | ||
"description": "Description" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
define('admin/settings/api', ['settings'], function (settings) { | ||
var ACP = {}; | ||
|
||
ACP.init = function () { | ||
const saveEl = $('#save'); | ||
settings.load('core.api', $('.core-api-settings')); | ||
saveEl.off('click'); // override settingsv1 handling | ||
$('#save').on('click', saveSettings); | ||
|
||
$(window).on('action:settings.sorted-list.loaded', (ev, { element }) => { | ||
element.addEventListener('click', (ev) => { | ||
if (ev.target.closest('input[readonly]')) { | ||
// Select entire input text | ||
ev.target.selectionStart = 0; | ||
ev.target.selectionEnd = ev.target.value.length; | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
function saveSettings() { | ||
settings.save('core.api', $('.core-api-settings'), function () { | ||
app.alert({ | ||
type: 'success', | ||
alert_id: 'core.api-saved', | ||
title: 'Settings Saved', | ||
timeout: 5000, | ||
}); | ||
ajaxify.refresh(); | ||
}); | ||
} | ||
|
||
return ACP; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<form> | ||
<input type="hidden" name="token"> | ||
<div class="form-group"> | ||
<label for="uid">[[admin/settings/api:uid]]</label> | ||
<input type="number" name="uid" class="form-control" placeholder="1" min="0" /> | ||
<p class="help-text"> | ||
[[admin/settings/api:uid-help-text]] | ||
</p> | ||
</div> | ||
<div class="form-group"> | ||
<label for="description">[[admin/settings/api:description]]</label> | ||
<input type="text" name="description" class="form-control" placeholder="Description" /> | ||
</div> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<li data-type="item" class="list-group-item"> | ||
<div class="row"> | ||
<div class="col-xs-9"> | ||
<span class="label label-primary">{{{ if uid }}}uid {uid}{{{ else }}}master{{{ end }}}</span> | ||
{{{ if token }}}<input type="text" readonly="readonly" value="{token}" size="32" />{{{ else }}}<em class="text-warning">Token will be generated once form is saved</em>{{{ end }}}<br /> | ||
<small>{description}</small> | ||
</div> | ||
<div class="col-xs-3 text-right"> | ||
<button type="button" data-type="edit" class="btn btn-info">Edit</button> | ||
<button type="button" data-type="remove" class="btn btn-danger">Delete</button> | ||
</div> | ||
</div> | ||
</li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!-- IMPORT admin/partials/settings/header.tpl --> | ||
|
||
<form role="form" class="core-api-settings"> | ||
<div class="row"> | ||
<div class="col-sm-2 col-xs-12 settings-header">[[admin/settings/api:tokens]]</div> | ||
<div class="col-sm-10 col-xs-12"> | ||
<p class="lead">[[admin/settings/api:lead-text]]</p> | ||
<p>[[admin/settings/api:intro]]</p> | ||
<p> | ||
<a href="https://docs.nodebb.org/api"> | ||
<i class="fa fa-external-link"></i> | ||
[[admin/settings/api:docs]] | ||
</a> | ||
</p> | ||
|
||
<div class="form-group" data-type="sorted-list" data-sorted-list="tokens" data-item-template="admin/partials/api/sorted-list/item" data-form-template="admin/partials/api/sorted-list/form"> | ||
<input hidden="text" name="tokens"> | ||
<ul data-type="list" class="list-group"></ul> | ||
<button type="button" data-type="add" class="btn btn-info">Create Token</button> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
|
||
<!-- IMPORT admin/partials/settings/footer.tpl --> |