|
@@ -7,6 +7,8 @@ import (
|
|
"fmt"
|
|
"fmt"
|
|
"io"
|
|
"io"
|
|
"net/http"
|
|
"net/http"
|
|
|
|
+ "net/url"
|
|
|
|
+ "strings"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
)
|
|
@@ -41,8 +43,22 @@ func forwardRequestWithJWT(c *gin.Context, targetURL string) (interface{}, error
|
|
|
|
|
|
req.Header.Set("Authorization", jwtToken)
|
|
req.Header.Set("Authorization", jwtToken)
|
|
|
|
|
|
- // Set content type if it's a POST request
|
|
|
|
- if c.Request.Method == "POST" {
|
|
|
|
|
|
+ // Copy the original content type, unless it's the set-password endpoint
|
|
|
|
+ if strings.Contains(targetURL, "/api/set-password") {
|
|
|
|
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
+ // Parse JSON body and convert to form data
|
|
|
|
+ if len(bodyBytes) > 0 {
|
|
|
|
+ var jsonData map[string]interface{}
|
|
|
|
+ if err := json.Unmarshal(bodyBytes, &jsonData); err != nil {
|
|
|
|
+ return nil, fmt.Errorf("parse json error: %v", err)
|
|
|
|
+ }
|
|
|
|
+ formData := url.Values{}
|
|
|
|
+ for k, v := range jsonData {
|
|
|
|
+ formData.Set(k, fmt.Sprintf("%v", v))
|
|
|
|
+ }
|
|
|
|
+ req.Body = io.NopCloser(strings.NewReader(formData.Encode()))
|
|
|
|
+ }
|
|
|
|
+ } else if c.Request.Method == "POST" {
|
|
req.Header.Set("Content-Type", "application/json")
|
|
req.Header.Set("Content-Type", "application/json")
|
|
}
|
|
}
|
|
|
|
|