Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant