mirror of
https://github.com/Li4n0/revsuit.git
synced 2026-09-21 22:30:46 +08:00
fix: fix the bug that authentication always fails after token change (#59)
This commit is contained in:
@@ -18,7 +18,7 @@ import (
|
|||||||
|
|
||||||
func (revsuit *Revsuit) auth(c *gin.Context) {
|
func (revsuit *Revsuit) auth(c *gin.Context) {
|
||||||
c.SetSameSite(http.SameSiteLaxMode)
|
c.SetSameSite(http.SameSiteLaxMode)
|
||||||
c.SetCookie("token", c.Request.Header["Token"][0], 0, revsuit.config.AdminPathPrefix, "", false, true)
|
c.SetCookie("token", c.Request.Header.Get("Token"), 0, revsuit.config.AdminPathPrefix, "", false, true)
|
||||||
c.String(200, "pong")
|
c.String(200, "pong")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,13 +32,12 @@ func (revsuit *Revsuit) registerPlatformRouter() {
|
|||||||
// /api need Authorization
|
// /api need Authorization
|
||||||
api := revsuit.http.Router.Group(revsuit.config.AdminPathPrefix + "/api")
|
api := revsuit.http.Router.Group(revsuit.config.AdminPathPrefix + "/api")
|
||||||
api.Use(func(c *gin.Context) {
|
api.Use(func(c *gin.Context) {
|
||||||
token, err := c.Cookie("token")
|
token, _ := c.Cookie("token")
|
||||||
if err == http.ErrNoCookie {
|
|
||||||
token = c.Request.Header.Get("Token")
|
|
||||||
}
|
|
||||||
if token != revsuit.http.Token {
|
if token != revsuit.http.Token {
|
||||||
c.Abort()
|
if c.Request.Header.Get("Token") != revsuit.http.Token {
|
||||||
c.Status(403)
|
c.Abort()
|
||||||
|
c.Status(403)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
revsuit.http.ApiGroup = api
|
revsuit.http.ApiGroup = api
|
||||||
|
|||||||
Reference in New Issue
Block a user