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

Commit 842a30a

Browse files
committed
Improve GF version, fix blacklist errors, modify examples.
1 parent 4c4bb92 commit 842a30a

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

auth_jwt.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,12 @@ func (mw *GfJWTMiddleware) setBlacklist(token string, claims jwt.MapClaims) erro
680680

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

683-
// Global gcache
684-
err = blacklist.Set(token, true, time.Unix(exp, 0).Sub(mw.TimeFunc()).Truncate(time.Second))
683+
// save duration time = (exp + max_refresh) - now
684+
duration := time.Unix(exp, 0).Add(mw.MaxRefresh).Sub(mw.TimeFunc()).Truncate(time.Second)
685+
686+
// global gcache
687+
err = blacklist.Set(token, true, duration)
688+
685689
if err != nil {
686690
return err
687691
}

example/main.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ func middlewareAuth(r *ghttp.Request) {
1616
func main() {
1717
s := g.Server()
1818
s.BindHandler("/", api.Work.Works)
19-
s.BindHandler("POST:/login", api.Auth.LoginHandler)
19+
s.Group("/", func(g *ghttp.RouterGroup) {
20+
g.ALL("/login", api.Auth.LoginHandler)
21+
g.ALL("/refresh_token", api.Auth.RefreshHandler)
22+
g.ALL("/logout", api.Auth.LogoutHandler)
23+
})
2024
s.Group("/user", func(g *ghttp.RouterGroup) {
2125
g.Middleware(service.Middleware.CORS, middlewareAuth)
2226
g.ALL("/info", api.Work.Info)
23-
g.ALL("/refresh_token", api.Auth.RefreshHandler)
24-
g.ALL("/logout", api.Auth.LogoutHandler)
2527
})
26-
s.SetPort(8000)
28+
s.SetPort(8111)
2729
s.Run()
2830
}

go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module github.com/gogf/gf-jwt
22

33
require (
44
github.com/dgrijalva/jwt-go v3.2.0+incompatible
5-
github.com/gogf/gf v1.15.1
5+
github.com/gogf/gf v1.15.3
6+
github.com/mattn/go-runewidth v0.0.12 // indirect
67
)
78

89
go 1.10

0 commit comments

Comments
 (0)