From fc39d84942dfa796f0f48c110aa5f069098b9069 Mon Sep 17 00:00:00 2001 From: lbw Date: Fri, 7 Apr 2023 16:56:37 +0800 Subject: [PATCH] =?UTF-8?q?ref:=20=E7=BB=86=E8=8A=82=E4=BC=98=E5=8C=96?= =?UTF-8?q?=EF=BC=8C=E5=A4=B4=E5=83=8F=E4=B8=8A=E4=BC=A0=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=20api=20prefix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/login/index.ts | 20 +++++++++++--------- src/components/Upload/Image.vue | 3 ++- src/utils/request.ts | 8 ++++---- src/views/home/current-user.vue | 5 ++++- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/api/login/index.ts b/src/api/login/index.ts index a5bf789a..091ab499 100644 --- a/src/api/login/index.ts +++ b/src/api/login/index.ts @@ -3,6 +3,12 @@ import { Session } from '/@/utils/storage'; import { validateNull } from '/@/utils/validate'; import { useUserInfo } from '/@/stores/userInfo'; +/** + * https://www.ietf.org/rfc/rfc6749.txt + * OAuth 协议 4.3.1 要求格式为 form 而不是 JSON 注意! + */ +const FORM_CONTENT_TYPE = 'application/x-www-form-urlencoded'; + /** * 登录 * @param data @@ -18,9 +24,8 @@ export const login = (data: any) => { data: { password: password }, headers: { skipToken: true, - 'TENANT-ID': '1', Authorization: basicAuth, - 'Content-Type': 'application/x-www-form-urlencoded', + 'Content-Type': FORM_CONTENT_TYPE, }, }); }; @@ -35,9 +40,8 @@ export const loginByMobile = (mobile: any, code: any) => { url: '/auth/oauth2/token', headers: { skipToken: true, - 'TENANT-ID': '1', Authorization: basicAuth, - 'Content-Type': 'application/x-www-form-urlencoded', + 'Content-Type': FORM_CONTENT_TYPE, }, method: 'post', params: { mobile: 'SMS@' + mobile, code: code, grant_type, scope }, @@ -54,9 +58,8 @@ export const loginBySocial = (state: string, code: string) => { url: '/auth/oauth2/token', headers: { skipToken: true, - 'TENANT-ID': '1', Authorization: basicAuth, - 'Content-Type': 'application/x-www-form-urlencoded', + 'Content-Type': FORM_CONTENT_TYPE, }, method: 'post', params: { mobile: state + '@' + code, code: code, grant_type, scope }, @@ -80,9 +83,8 @@ export const refreshTokenApi = (refresh_token: string) => { url: '/auth/oauth2/token', headers: { skipToken: true, - 'TENANT-ID': '1', Authorization: basicAuth, - 'Content-Type': 'application/x-www-form-urlencoded', + 'Content-Type': FORM_CONTENT_TYPE, }, method: 'post', params: { refresh_token, grant_type, scope }, @@ -100,7 +102,7 @@ export const checkToken = (refreshTime: number, refreshLock: boolean) => { headers: { skipToken: true, Authorization: basicAuth, - 'Content-Type': 'application/x-www-form-urlencoded', + 'Content-Type': FORM_CONTENT_TYPE, }, method: 'get', params: { token: Session.getToken() }, diff --git a/src/components/Upload/Image.vue b/src/components/Upload/Image.vue index 6e712795..b2ffbf81 100644 --- a/src/components/Upload/Image.vue +++ b/src/components/Upload/Image.vue @@ -15,7 +15,8 @@ :accept="fileType.join(',')" >