Add a JWT token authentication

This commit is contained in:
Olivier MICHAUD
2021-05-17 21:46:55 +02:00
parent 3c06736520
commit 1371d03fec
5 changed files with 200 additions and 4 deletions
+11
View File
@@ -5,11 +5,18 @@ import Debug from 'debug';
import http from 'http';
import { hri } from 'human-readable-ids';
import Router from 'koa-router';
import jwt from'koa-jwt';
import ClientManager from './lib/ClientManager';
const debug = Debug('localtunnel:server');
function addJwtMiddleware(app, opt) {
app.use(jwt({
secret: opt.jwt_shared_secret
}));
}
export default function(opt) {
opt = opt || {};
@@ -28,6 +35,10 @@ export default function(opt) {
const app = new Koa();
const router = new Router();
if (opt.jwt_shared_secret){
addJwtMiddleware(app, opt);
}
router.get('/api/status', async (ctx, next) => {
const stats = manager.stats;
ctx.body = {