Closed quentinalbertone closed 1 year ago
+1
@quentinalbertone
I have found a workaround that works for me, maybe a bit hacky, but try it.
func setupGoGuardian() {
keeper = jwt.StaticSecret{
ID: "secret-id",
Secret: []byte("secret"),
Algorithm: jwt.HS256,
}
cache := libcache.FIFO.New(0)
cache.SetTTL(time.Minute * 5)
chl := make(chan libcache.Event)
defer close(chl)
cache.Notify(chl, libcache.Remove)
go func(chl chan libcache.Event) {
event := <-chl
cache.Peek(event.Key)
}(chl)
basicStrategy := basic.NewCached(validateUser, cache)
jwtStrategy := jwt.New(cache, keeper)
strategy = union.New(jwtStrategy, basicStrategy)
}
Added also a PR https://github.com/shaj13/go-guardian/pull/122
@quentinalbertone
One more bug after, but then it sort of works. Apply the following change as well.
@quentinalbertone will update the example asap. @Ivasan7 thanks, will take a look into your PR,
with the new version of libcache you can clean the cache in two different mechanisms
Let the cache clean itself lazily on the read-write operation.
func setupGoGuardian() {
keeper = jwt.StaticSecret{
ID: "secret-id",
Secret: []byte("secret"),
Algorithm: jwt.HS256,
}
cache := libcache.FIFO.New(0)
cache.SetTTL(time.Minute * 5)
basicStrategy := basic.NewCached(validateUser, cache)
jwtStrategy := jwt.New(cache, keeper)
strategy = union.New(jwtStrategy, basicStrategy)
}
spawn a garbage collector to collect expired items on time
func setupGoGuardian() {
keeper = jwt.StaticSecret{
ID: "secret-id",
Secret: []byte("secret"),
Algorithm: jwt.HS256,
}
cache := libcache.FIFO.New(0)
cache.SetTTL(time.Minute * 5)
go libcache.GC(context.TODO(), cache)
basicStrategy := basic.NewCached(validateUser, cache)
jwtStrategy := jwt.New(cache, keeper)
strategy = union.New(jwtStrategy, basicStrategy)
}
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What version of Go-Guardian are you using ?
What did you do?
Hello, I just want to follow the jwt example https://github.com/shaj13/go-guardian/blob/master/_examples/jwt/main.go But the function
RegisterOnExpired
was deprecated and no-longer works. Can you update the example directory on this repo.What did you expect to see?
The program init and run
What did you see instead?