🎨 Authentication supports query parameters token (#9069)

This commit is contained in:
Yingyi / 颖逸 2023-08-29 16:16:33 +08:00 committed by GitHub
parent 2349b080db
commit 2bfefbe885
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 ")
@ -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