header.js 537 B

12345678910111213141516
  1. import {Base64} from 'js-base64';
  2. import website from '@/config/index';
  3. import {getToken} from '../util/auth';
  4. export function getTokenHeader(text= false) {
  5. let headers = {};
  6. headers['Authorization'] = `Basic ${Base64.encode(`${website.clientId}:${website.clientSecret}`)}`;
  7. //让每个请求携带token
  8. const token = getToken()
  9. if (token) headers['Blade-Auth'] = 'bearer ' + token
  10. //headers中配置text请求
  11. if (text === true) {
  12. headers["Content-Type"] = "text/plain";
  13. }
  14. return headers;
  15. }