Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token confusion. #4134

Open
iosplist opened this issue May 10, 2024 · 0 comments
Open

Token confusion. #4134

iosplist opened this issue May 10, 2024 · 0 comments

Comments

@iosplist
Copy link

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant