Skip to content

Commit

Permalink
fix: anonymity user
Browse files Browse the repository at this point in the history
  • Loading branch information
liaosunny123 committed Sep 1, 2023
1 parent 9cb52fb commit ed0581e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .env.docker.compose
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ RABBITMQ_VHOST_PREFIX=
CHATGPT_API_KEYS=
# Gorse provides recommend service for GuGoTik.
GORSE_ADDR=http://gorse-server:8087
GORSE_APIKEY=5105502fc46a411c896aa5b50c31e951
GORSE_APIKEY=5105502fc46a411c896aa5b50c31e951
ANONYMITY_USER=50
18 changes: 12 additions & 6 deletions src/web/middleware/authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@ func TokenAuthMiddleware() gin.HandlerFunc {
defer span.End()
logging.SetSpanWithHostname(span)
logger := logging.LogService("GateWay.AuthMiddleWare").WithContext(ctx)

span.SetAttributes(attribute.String("url", c.Request.URL.Path))
if c.Request.URL.Path == "/douyin/user/login/" ||
c.Request.URL.Path == "/douyin/user/register/" ||
c.Request.URL.Path == "/douyin/comment/list/" ||
c.Request.URL.Path == "/douyin/relation/follow/list/" ||
c.Request.URL.Path == "/douyin/publish/list/" ||
c.Request.URL.Path == "/douyin/favorite/list/" ||
c.Request.URL.Path == "/douyin/relation/follower/list/" {
c.Request.URL.Path == "/douyin/favorite/list/" {
c.Request.URL.RawQuery += "&actor_id=" + config.EnvCfg.AnonymityUser
c.Next()
span.SetAttributes(attribute.String("mark_url", c.Request.URL.String()))
logger.WithFields(logrus.Fields{
"Path": c.Request.URL.Path,
}).Debugf("Skip Auth with targeted url")
c.Next()
return
}

Expand All @@ -45,7 +44,14 @@ func TokenAuthMiddleware() gin.HandlerFunc {
token = c.Query("token")
}

if token == "" && c.Request.URL.Path == "/douyin/feed/" {
if token == "" && (c.Request.URL.Path == "/douyin/feed/" ||
c.Request.URL.Path == "/douyin/relation/follow/list/" ||
c.Request.URL.Path == "/douyin/relation/follower/list/") {
c.Request.URL.RawQuery += "&actor_id=" + config.EnvCfg.AnonymityUser
span.SetAttributes(attribute.String("mark_url", c.Request.URL.String()))
logger.WithFields(logrus.Fields{
"Path": c.Request.URL.Path,
}).Debugf("Skip Auth with targeted url")
c.Next()
return
}
Expand Down

0 comments on commit ed0581e

Please sign in to comment.