mirror of
https://github.com/xiaoxinpro/nginx-proxy-manager-zh.git
synced 2025-01-22 21:08:13 -05:00
Merge pull request #880 from jlesage/jwt-key-pair-no-restart
Removed the need to restart Nginx Proxy Manager after generating JWT key pair
This commit is contained in:
commit
6e67352a0f
@ -4,15 +4,23 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const config = require('config');
|
|
||||||
const jwt = require('jsonwebtoken');
|
const jwt = require('jsonwebtoken');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const error = require('../lib/error');
|
const error = require('../lib/error');
|
||||||
const ALGO = 'RS256';
|
const ALGO = 'RS256';
|
||||||
|
|
||||||
|
let public_key = null;
|
||||||
|
let private_key = null;
|
||||||
|
|
||||||
|
function checkJWTKeyPair() {
|
||||||
|
if (!public_key || !private_key) {
|
||||||
|
let config = require('config');
|
||||||
|
public_key = config.get('jwt.pub');
|
||||||
|
private_key = config.get('jwt.key');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
const public_key = config.get('jwt.pub');
|
|
||||||
const private_key = config.get('jwt.key');
|
|
||||||
|
|
||||||
let token_data = {};
|
let token_data = {};
|
||||||
|
|
||||||
@ -32,6 +40,8 @@ module.exports = function () {
|
|||||||
.toString('base64')
|
.toString('base64')
|
||||||
.substr(-8);
|
.substr(-8);
|
||||||
|
|
||||||
|
checkJWTKeyPair();
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
jwt.sign(payload, private_key, options, (err, token) => {
|
jwt.sign(payload, private_key, options, (err, token) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -53,6 +63,7 @@ module.exports = function () {
|
|||||||
*/
|
*/
|
||||||
load: function (token) {
|
load: function (token) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
checkJWTKeyPair();
|
||||||
try {
|
try {
|
||||||
if (!token || token === null || token === 'null') {
|
if (!token || token === null || token === 'null') {
|
||||||
reject(new error.AuthError('Empty token'));
|
reject(new error.AuthError('Empty token'));
|
||||||
|
@ -51,9 +51,8 @@ const setupJwt = () => {
|
|||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
logger.info('Wrote JWT key pair to config file: ' + filename);
|
logger.info('Wrote JWT key pair to config file: ' + filename);
|
||||||
|
delete require.cache[require.resolve('config')];
|
||||||
logger.warn('Restarting interface to apply new configuration');
|
resolve();
|
||||||
process.exit(0);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user