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

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

@fidding

Description

@fidding

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions