Skip to content

Commit

Permalink
Merge pull request #10 from SwanHubX/fit-oauth
Browse files Browse the repository at this point in the history
update: auth body struct
  • Loading branch information
swpfY authored Oct 16, 2023
2 parents a0e994e + ecc5b91 commit f6721ab
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/base64"
"encoding/json"
"encoding/pem"
"io"
"math"
"math/rand"
"net/http"
Expand Down Expand Up @@ -36,13 +37,6 @@ type Preprocess struct {
publicKey *rsa.PublicKey
}

// Response 响应对象
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
Data json.RawMessage `json:"data"`
}

// JWT JWT对象格式
type JWT struct {
header string
Expand Down Expand Up @@ -71,7 +65,7 @@ func (p *Preprocess) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
}

/*
将会话id转发给认证接口,用于检索会话信息传递给后面的真实接口
将会话id转发给认证接口,用于检索会话信息传递给后面的业务接口
会话id保留在cookie中的sid字段中
*/
func (p *Preprocess) forwardAuth(req *http.Request) {
Expand All @@ -89,12 +83,12 @@ func (p *Preprocess) forwardAuth(req *http.Request) {
return
}
defer res.Body.Close()
// 处理响应,转化为JSON
var result Response
if err := json.NewDecoder(res.Body).Decode(&result); err != nil || result.Code != 0 {
// 读取响应体
result, err := io.ReadAll(res.Body)
if res.StatusCode != 200 || err != nil {
return
}
req.Header.Add("Payload", string(result.Data))
req.Header.Add("Payload", string(result))
}

// ----- JWT相关 -----
Expand Down

0 comments on commit f6721ab

Please sign in to comment.