mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 02:13:57 +00:00
shouldAuthorizeApi refactor
This commit is contained in:
@@ -10,10 +10,6 @@ const { create } = require('lodash');
|
|||||||
|
|
||||||
const logger = getLogger('auth');
|
const logger = getLogger('auth');
|
||||||
|
|
||||||
function shouldAuthorizeApi() {
|
|
||||||
return createAuthProvider().shouldAuthorizeApi();
|
|
||||||
}
|
|
||||||
|
|
||||||
function unauthorizedResponse(req, res, text) {
|
function unauthorizedResponse(req, res, text) {
|
||||||
// if (req.path == getExpressPath('/config/get-settings')) {
|
// if (req.path == getExpressPath('/config/get-settings')) {
|
||||||
// return res.json({});
|
// return res.json({});
|
||||||
@@ -27,7 +23,7 @@ function unauthorizedResponse(req, res, text) {
|
|||||||
function authMiddleware(req, res, next) {
|
function authMiddleware(req, res, next) {
|
||||||
const SKIP_AUTH_PATHS = ['/config/get', '/auth/oauth-token', '/auth/login', '/stream'];
|
const SKIP_AUTH_PATHS = ['/config/get', '/auth/oauth-token', '/auth/login', '/stream'];
|
||||||
|
|
||||||
if (!shouldAuthorizeApi()) {
|
if (!createAuthProvider().shouldAuthorizeApi()) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
let skipAuth = !!SKIP_AUTH_PATHS.find(x => req.path == getExpressPath(x));
|
let skipAuth = !!SKIP_AUTH_PATHS.find(x => req.path == getExpressPath(x));
|
||||||
@@ -68,5 +64,4 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
authMiddleware,
|
authMiddleware,
|
||||||
shouldAuthorizeApi,
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -85,9 +85,7 @@ function start() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auth.shouldAuthorizeApi()) {
|
app.use(auth.authMiddleware);
|
||||||
app.use(auth.authMiddleware);
|
|
||||||
}
|
|
||||||
|
|
||||||
app.get(getExpressPath('/stream'), async function (req, res) {
|
app.get(getExpressPath('/stream'), async function (req, res) {
|
||||||
const strmid = req.query.strmid;
|
const strmid = req.query.strmid;
|
||||||
|
|||||||
Reference in New Issue
Block a user