Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

LogoutHandler黑名单缓存时间计算不正确 #32

Open
fidding opened this issue Jun 21, 2024 · 0 comments
Open

LogoutHandler黑名单缓存时间计算不正确 #32

fidding opened this issue Jun 21, 2024 · 0 comments

Comments

@fidding
Copy link

fidding commented Jun 21, 2024

LogoutHandler黑名单缓存时间计算不正确

image

func (mw *GfJWTMiddleware) setBlacklist(ctx context.Context, token string, claims jwt.MapClaims) error {
	// The goal of MD5 is to reduce the key length.
	token, err := gmd5.EncryptString(token)

	if err != nil {
		return err
	}

	exp := int64(claims["exp"].(float64))

	// save duration time = (exp + max_refresh) - now
	duration := time.Unix(exp, 0).Add(mw.MaxRefresh).Sub(mw.TimeFunc()).Truncate(time.Second)

	key := mw.BlacklistPrefix + token
	// global gcache
	err = blacklist.Set(ctx, key, true, duration)

	if err != nil {
		return err
	}

	return nil
}

其中exp是毫秒,在执行time.Unix的第一个参数单位是秒,就会导致算出来的时间多了3个0

于是写入数据库的缓存时间就会是292yr

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant