mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 06:46:09 +08:00
修复token验证
This commit is contained in:
parent
ef16622a7e
commit
0c3b3c206e
|
@ -111,3 +111,11 @@ export function createRandomString(min: number, max: number): string {
|
|||
|
||||
return newArr.join('');
|
||||
}
|
||||
|
||||
export function getToken(req: any) {
|
||||
const { authorization } = req.headers;
|
||||
if (authorization && authorization.split(' ')[0] === 'Bearer') {
|
||||
return authorization.split(' ')[1];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import routes from '../api';
|
|||
import config from '../config';
|
||||
import jwt from 'express-jwt';
|
||||
import fs from 'fs';
|
||||
import { getToken } from '../config/util';
|
||||
|
||||
export default ({ app }: { app: Application }) => {
|
||||
app.enable('trust proxy');
|
||||
|
@ -22,10 +23,10 @@ export default ({ app }: { app: Application }) => {
|
|||
return next();
|
||||
}
|
||||
const data = fs.readFileSync(config.authConfigFile, 'utf8');
|
||||
const authHeader = req.headers.authorization;
|
||||
const headerToken = getToken(req);
|
||||
if (data) {
|
||||
const { token } = JSON.parse(data);
|
||||
if (token && authHeader.includes(token)) {
|
||||
if (token && headerToken === token) {
|
||||
return next();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user