go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

Token confusion.

Open iosplist opened this issue 1 month ago • 0 comments

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior, if applicable:

  1. The code is

    
    

func (m *OplogMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { body := "" if r.Method == http.MethodPost { bf := bytes.NewBuffer(nil) wt := bufio.NewWriter(bf) io.Copy(wt, r.Body) rb, _ := io.ReadAll(bf) r.Body = io.NopCloser(bytes.NewBuffer(rb)) body = string(rb) }

	next(w, r)
	if len(r.Header.Get("Authorization")) > 0 {
		ut, _ := jwtx.GetUserType(r.Context())

		deptLv := permissions.GetDeptLvl(r.Context(), m.Redis)
		shopUniqueKey := ""
		//门店用户
		if deptLv == "3" {
			shopUniqueKeys := permissions.GetShopsUniqueKey(r.Context(), m.Redis)
			if len(shopUniqueKeys) > 0 {
				shopUniqueKey = shopUniqueKeys[0]
			}
		}

		m.OplogRpc.AddSysLog(r.Context(), &oplog.AddSysLogRequest{
			Info: &oplog.SysLog{
				UserUniqueKey: jwtx.GetUID(r.Context()),
				UserName:      jwtx.GetUserName(r.Context()),
				ShopUniqueKey: shopUniqueKey,
				Ip:            tool.GetRemoteClientIp(r),
				Uri:           r.RequestURI,
				Method:        r.Method,
				Type:          ut,
				Request:       body,
			},
		})
	}
}

}


2. The error is

The token obtained from the header belongs to someone else.


**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Environments (please complete the following information):**
- OS: [e.g. Linux]
- go-zero version [e.g. 1.2.1]
- goctl version [e.g. 1.2.1, optional]

**More description**
Add any other context about the problem here.

iosplist avatar May 10 '24 02:05 iosplist