File tree Expand file tree Collapse file tree 3 files changed +12
-24
lines changed
Expand file tree Collapse file tree 3 files changed +12
-24
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ go 1.24.0
44
55require (
66 github.com/cybertec-postgresql/pgx-migrator v1.1.0
7- github.com/golang-jwt/jwt v3 .2.2+incompatible
7+ github.com/golang-jwt/jwt/v5 v5 .2.2
88 github.com/gorilla/websocket v1.5.3
99 github.com/jackc/pgx/v5 v5.7.4
1010 github.com/jessevdk/go-flags v1.6.1
Original file line number Diff line number Diff line change @@ -53,8 +53,8 @@ github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW
5353github.com/godbus/dbus/v5 v5.0.4 /go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA =
5454github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q =
5555github.com/gogo/protobuf v1.3.2 /go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q =
56- github.com/golang-jwt/jwt v3 .2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY =
57- github.com/golang-jwt/jwt v3 .2.2+incompatible /go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I =
56+ github.com/golang-jwt/jwt/v5 v5 .2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8 =
57+ github.com/golang-jwt/jwt/v5 v5 .2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk =
5858github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek =
5959github.com/golang/protobuf v1.5.4 /go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps =
6060github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8 =
Original file line number Diff line number Diff line change 77 "net/http"
88 "time"
99
10- "github.com/golang-jwt/jwt"
10+ "github.com/golang-jwt/jwt/v5 "
1111)
1212
1313type loginReq struct {
@@ -92,24 +92,12 @@ func validateToken(r *http.Request) (err error) {
9292 if t == "" {
9393 return errors .New ("can not find token in header" )
9494 }
95- token , err := jwt .Parse (t , func (token * jwt.Token ) (interface {}, error ) {
96- if _ , ok := token .Method .(* jwt.SigningMethodHMAC ); ! ok {
97- return nil , errors .New ("there was an error in parsing" )
98- }
99- return sampleSecretKey , nil
100- })
101- if err != nil {
102- return err
103- }
104- if token == nil {
105- return errors .New ("invalid token" )
106- }
107- claims , ok := token .Claims .(jwt.MapClaims )
108- if ! ok {
109- return errors .New ("cannot parse token claims" )
110- }
111- if ! claims .VerifyExpiresAt (time .Now ().Local ().Unix (), true ) {
112- return errors .New ("token expired" )
113- }
114- return nil
95+
96+ _ , err = jwt .Parse (t ,
97+ func (token * jwt.Token ) (any , error ) {
98+ return sampleSecretKey , nil
99+ },
100+ jwt .WithExpirationRequired (),
101+ jwt .WithValidMethods ([]string {jwt .SigningMethodHS256 .Alg ()}))
102+ return err
115103}
You can’t perform that action at this time.
0 commit comments