mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 Improve API Token authentication https://github.com/siyuan-note/siyuan/issues/10792
This commit is contained in:
parent
7d2d76c57c
commit
c0a10ab98c
1 changed files with 11 additions and 1 deletions
|
|
@ -235,8 +235,18 @@ func CheckAuth(c *gin.Context) {
|
||||||
|
|
||||||
// 通过 API token (header: Authorization)
|
// 通过 API token (header: Authorization)
|
||||||
if authHeader := c.GetHeader("Authorization"); "" != authHeader {
|
if authHeader := c.GetHeader("Authorization"); "" != authHeader {
|
||||||
|
var token string
|
||||||
if strings.HasPrefix(authHeader, "Token ") {
|
if strings.HasPrefix(authHeader, "Token ") {
|
||||||
token := strings.TrimPrefix(authHeader, "Token ")
|
token = strings.TrimPrefix(authHeader, "Token ")
|
||||||
|
} else if strings.HasPrefix(authHeader, "token ") {
|
||||||
|
token = strings.TrimPrefix(authHeader, "token ")
|
||||||
|
} else if strings.HasPrefix(authHeader, "Bearer ") {
|
||||||
|
token = strings.TrimPrefix(authHeader, "Bearer ")
|
||||||
|
} else if strings.HasPrefix(authHeader, "bearer ") {
|
||||||
|
token = strings.TrimPrefix(authHeader, "bearer ")
|
||||||
|
}
|
||||||
|
|
||||||
|
if "" != token {
|
||||||
if Conf.Api.Token == token {
|
if Conf.Api.Token == token {
|
||||||
c.Next()
|
c.Next()
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue