checkAuth.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package middleware
  2. //type CustomResponseWriter struct {
  3. // gin.ResponseWriter
  4. // body *bytes.Buffer
  5. // Host string
  6. //}
  7. //
  8. //func (w CustomResponseWriter) Write(b []byte) (int, error) {
  9. // w.body.Write(b)
  10. // if strings.Contains(w.Host, "cloud.long-chi.com") {
  11. // old := string(b)
  12. // //为兼容https,此处需要修改下
  13. // new := strings.ReplaceAll(old, "http://110.40.223.170:9000/", "https://cloud.long-chi.com/")
  14. // new = strings.ReplaceAll(new, "http://106.52.134.22:9099/", "https://cloud.long-chi.com/")
  15. // b = []byte(new)
  16. // }
  17. // return w.ResponseWriter.Write(b)
  18. //}
  19. //
  20. //func (w CustomResponseWriter) WriteString(s string) (int, error) {
  21. // w.body.WriteString(s)
  22. // return w.ResponseWriter.WriteString(s)
  23. //}
  24. //func CheckAuth() gin.HandlerFunc {
  25. // return func(ctx *gin.Context) {
  26. // //该路由下不校验token
  27. // if strings.Contains(ctx.Request.RequestURI, "/login") ||
  28. // strings.Contains(ctx.Request.RequestURI, "/captcha") ||
  29. // strings.Contains(ctx.Request.RequestURI, "/tenant/info") ||
  30. // strings.Contains(ctx.Request.RequestURI, "/api/ctwing/aep/callback") ||
  31. // strings.Contains(ctx.Request.RequestURI, "/token") {
  32. // ctx.Next()
  33. // return
  34. // }
  35. //
  36. // authorization := ctx.GetHeader(Authorization)
  37. // if authorization != "" {
  38. // token := ParseAccessToken(authorization)
  39. // if token != nil {
  40. // ctx.Set(Authorization, token)
  41. //
  42. // blw := &CustomResponseWriter{body: bytes.NewBufferString(""), ResponseWriter: ctx.Writer, Host: ctx.Request.Host}
  43. // ctx.Writer = blw
  44. // ctx.Next()
  45. // return
  46. // }
  47. // }
  48. // ctx.JSON(http.StatusUnauthorized, common.NormalResponse(http.StatusUnauthorized, "token is invalid", nil))
  49. // ctx.Abort()
  50. // }
  51. //}