Skip to content

Commit

Permalink
🎨 Authentication supports query parameters token (#9069)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuoqiu-Yingyi authored Aug 29, 2023
1 parent 2349b08 commit 2bfefbe
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion kernel/model/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func CheckAuth(c *gin.Context) {
return
}

// 通过 API token
// 通过 API token (header: Authorization)
if authHeader := c.GetHeader("Authorization"); "" != authHeader {
if strings.HasPrefix(authHeader, "Token ") {
token := strings.TrimPrefix(authHeader, "Token ")
Expand All @@ -210,6 +210,18 @@ func CheckAuth(c *gin.Context) {
}
}

// 通过 API token (query-params: token)
if token := c.Query("token"); "" != token {
if Conf.Api.Token == token {
c.Next()
return
}

c.JSON(401, map[string]interface{}{"code": -1, "msg": "Auth failed"})
c.Abort()
return
}

if "/check-auth" == c.Request.URL.Path { // 跳过访问授权页
c.Next()
return
Expand Down

0 comments on commit 2bfefbe

Please sign in to comment.