enahnce(security):改进对于令牌的获取。

This commit is contained in:
徐涛 2023-06-11 17:35:50 +08:00
parent 5d938da53e
commit c2a56c8253

View File

@ -14,7 +14,11 @@ import (
// ! 仅通过该中间件是不能保证上下文中一定保存有用户会话信息的。
func SessionRecovery(c *fiber.Ctx) error {
if auth := c.Get("Authorization", ""); len(auth) > 0 {
token := strings.Fields(auth)[1]
authFields := strings.Fields(auth)
if len(authFields) != 2 || strings.ToLower(authFields[0]) != "bearer" || len(authFields[1]) == 0 {
return c.Next()
}
token := authFields[1]
session, err := cache.RetrieveSession(token)
if err == nil && session != nil {