Browse Source

token新增加密配置,保护接口安全

fix_bug_pro20231227
smallchill 1 year ago
parent
commit
a581d842a4
  1. 5
      src/api/desk/notice.js
  2. 12
      src/axios.js

5
src/api/desk/notice.js

@ -9,6 +9,7 @@ export const getList = (current, size, params) => {
current,
size,
},
cryptoToken: true,
});
};
@ -19,6 +20,7 @@ export const remove = ids => {
params: {
ids,
},
cryptoToken: true,
});
};
@ -27,6 +29,7 @@ export const add = row => {
url: '/blade-desk/notice/submit',
method: 'post',
data: row,
cryptoToken: true,
});
};
@ -35,6 +38,7 @@ export const update = row => {
url: '/blade-desk/notice/submit',
method: 'post',
data: row,
cryptoToken: true,
});
};
@ -45,5 +49,6 @@ export const getNotice = id => {
params: {
id,
},
cryptoToken: true,
});
};

12
src/axios.js

@ -17,6 +17,7 @@ import NProgress from 'nprogress'; // progress bar
import 'nprogress/nprogress.css'; // progress bar style
import { Base64 } from 'js-base64';
import { baseUrl } from '@/config/env';
import crypto from '@/utils/crypto';
axios.defaults.timeout = 10000;
//返回其他状态吗
@ -45,11 +46,16 @@ axios.interceptors.request.use(
`${website.clientId}:${website.clientSecret}`
)}`;
}
//让每个请求携带token
//headers判断请求是否携带token
const meta = config.meta || {};
const isToken = meta.isToken === false;
if (getToken() && !isToken) {
config.headers[website.tokenHeader] = 'bearer ' + getToken();
//headers传递token是否加密
const cryptoToken = config.cryptoToken === true;
const token = getToken();
if (token && !isToken) {
config.headers[website.tokenHeader] = cryptoToken
? 'crypto ' + crypto.encrypt(token)
: 'bearer ' + token;
}
//headers中配置text请求
if (config.text === true) {

Loading…
Cancel
Save