From 55c8126a3e7fb2350ce5c86da8d371818c770864 Mon Sep 17 00:00:00 2001 From: dingzy Date: Fri, 25 Oct 2024 16:47:52 +0800 Subject: [PATCH] change oauth2 token request param type to FormData --- knife4j-vue/public/oauth/oauth2.html | 14 +++++++------- knife4j-vue3/public/oauth/oauth2.html | 16 +++++++--------- .../src/main/resources/webjars/oauth/oauth2.html | 14 +++++++------- .../src/main/resources/webjars/oauth/oauth2.html | 15 +++++++-------- 4 files changed, 28 insertions(+), 31 deletions(-) diff --git a/knife4j-vue/public/oauth/oauth2.html b/knife4j-vue/public/oauth/oauth2.html index 9396bee18..813e67b8b 100644 --- a/knife4j-vue/public/oauth/oauth2.html +++ b/knife4j-vue/public/oauth/oauth2.html @@ -65,11 +65,12 @@ var that=this; console.log(this.cacheValue); var url=this.cacheValue.tokenUrl; - var params={ - "grant_type":"authorization_code", - "code":this.code, - "redirect_uri":decodeURIComponent(this.cacheValue.redirectUri), - } + var formData = new FormData(); + formData.append("grant_type", "authorization_code"); + formData.append("code", this.code); + formData.append("redirect_uri", decodeURIComponent(this.cacheValue.redirectUri)); + formData.append("client_id", this.cacheValue.clientId); + formData.append("client_secret", this.cacheValue.clientSecret); let instance=axios.create(); let requestConfig={ url: url, @@ -77,8 +78,7 @@ timeout: 0, //此data必传,不然默认是data:undefined,https://github.com/axios/axios/issues/86 //否则axios会忽略请求头Content-Type - data: `client_id=${this.cacheValue.clientId}&client_secret=${this.cacheValue.clientSecret}`, - params:params + data: formData } instance.request(requestConfig).then(res=>{ let data=res.data; diff --git a/knife4j-vue3/public/oauth/oauth2.html b/knife4j-vue3/public/oauth/oauth2.html index 55b436163..813e67b8b 100644 --- a/knife4j-vue3/public/oauth/oauth2.html +++ b/knife4j-vue3/public/oauth/oauth2.html @@ -65,13 +65,12 @@ var that=this; console.log(this.cacheValue); var url=this.cacheValue.tokenUrl; - var params={ - "grant_type":"authorization_code", - "code":this.code, - "redirect_uri":decodeURIComponent(this.cacheValue.redirectUri), - "client_id":this.cacheValue.clientId, - "client_secret":this.cacheValue.clientSecret - } + var formData = new FormData(); + formData.append("grant_type", "authorization_code"); + formData.append("code", this.code); + formData.append("redirect_uri", decodeURIComponent(this.cacheValue.redirectUri)); + formData.append("client_id", this.cacheValue.clientId); + formData.append("client_secret", this.cacheValue.clientSecret); let instance=axios.create(); let requestConfig={ url: url, @@ -79,8 +78,7 @@ timeout: 0, //此data必传,不然默认是data:undefined,https://github.com/axios/axios/issues/86 //否则axios会忽略请求头Content-Type - data: null, - params:params + data: formData } instance.request(requestConfig).then(res=>{ let data=res.data; diff --git a/knife4j/knife4j-openapi2-ui/src/main/resources/webjars/oauth/oauth2.html b/knife4j/knife4j-openapi2-ui/src/main/resources/webjars/oauth/oauth2.html index 9396bee18..813e67b8b 100644 --- a/knife4j/knife4j-openapi2-ui/src/main/resources/webjars/oauth/oauth2.html +++ b/knife4j/knife4j-openapi2-ui/src/main/resources/webjars/oauth/oauth2.html @@ -65,11 +65,12 @@ var that=this; console.log(this.cacheValue); var url=this.cacheValue.tokenUrl; - var params={ - "grant_type":"authorization_code", - "code":this.code, - "redirect_uri":decodeURIComponent(this.cacheValue.redirectUri), - } + var formData = new FormData(); + formData.append("grant_type", "authorization_code"); + formData.append("code", this.code); + formData.append("redirect_uri", decodeURIComponent(this.cacheValue.redirectUri)); + formData.append("client_id", this.cacheValue.clientId); + formData.append("client_secret", this.cacheValue.clientSecret); let instance=axios.create(); let requestConfig={ url: url, @@ -77,8 +78,7 @@ timeout: 0, //此data必传,不然默认是data:undefined,https://github.com/axios/axios/issues/86 //否则axios会忽略请求头Content-Type - data: `client_id=${this.cacheValue.clientId}&client_secret=${this.cacheValue.clientSecret}`, - params:params + data: formData } instance.request(requestConfig).then(res=>{ let data=res.data; diff --git a/knife4j/knife4j-openapi3-ui/src/main/resources/webjars/oauth/oauth2.html b/knife4j/knife4j-openapi3-ui/src/main/resources/webjars/oauth/oauth2.html index 5c3f0513f..a5e33ad3a 100644 --- a/knife4j/knife4j-openapi3-ui/src/main/resources/webjars/oauth/oauth2.html +++ b/knife4j/knife4j-openapi3-ui/src/main/resources/webjars/oauth/oauth2.html @@ -65,13 +65,12 @@ var that=this; console.log(this.cacheValue); var url=this.cacheValue.tokenUrl; - var params={ - "grant_type":"authorization_code", - "code":this.code, - "redirect_uri":decodeURIComponent(this.cacheValue.redirectUri), - "client_id":`${this.cacheValue.clientId}`, - "client_secret":`${this.cacheValue.clientSecret}` - } + var formData = new FormData(); + formData.append("grant_type", "authorization_code"); + formData.append("code", this.code); + formData.append("redirect_uri", decodeURIComponent(this.cacheValue.redirectUri)); + formData.append("client_id", this.cacheValue.clientId); + formData.append("client_secret", this.cacheValue.clientSecret); let instance=axios.create(); let requestConfig={ url: url, @@ -80,7 +79,7 @@ //此data必传,不然默认是data:undefined,https://github.com/axios/axios/issues/86 //否则axios会忽略请求头Content-Type // spring-authorization-server only support get param form request body,see https://github.com/spring-projects/spring-authorization-server/issues/1451 - data: params, + data: formData, // params:params } instance.request(requestConfig).then(res=>{