Skip to content

Commit

Permalink
deps:update jwt v4 ->v5 (#3085)
Browse files Browse the repository at this point in the history
* deps:update jwt v4 ->v5

* update logic

* deps:update jwt v4 ->v5

* update logic

* update go.mod

---------

Co-authored-by: wudongdong <[email protected]>
Co-authored-by: Cluas <[email protected]>
Co-authored-by: Weizhen Wang <[email protected]>
  • Loading branch information
4 people authored Dec 9, 2023
1 parent 69268c5 commit 7e2edec
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/fsnotify/fsnotify v1.6.0
github.com/go-kratos/aegis v0.2.0
github.com/go-playground/form/v4 v4.2.0
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/golang-jwt/jwt/v5 v5.1.0
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
github.com/imdario/mergo v0.3.16
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBY
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/form/v4 v4.2.0 h1:N1wh+Goz61e6w66vo8vJkQt+uwZSoLz50kZPJWR8eic=
github.com/go-playground/form/v4 v4.2.0/go.mod h1:q1a2BY+AQUUzhl6xA/6hBetay6dEIhMHjgvJiGo6K7U=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-jwt/jwt/v5 v5.1.0 h1:UGKbA/IPjtS6zLcdB7i5TyACMgSbOTiR8qzXgw8HWQU=
github.com/golang-jwt/jwt/v5 v5.1.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
Expand Down
14 changes: 4 additions & 10 deletions middleware/auth/jwt/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"strings"

"github.com/golang-jwt/jwt/v4"
"github.com/golang-jwt/jwt/v5"

"github.com/go-kratos/kratos/v2/errors"
"github.com/go-kratos/kratos/v2/middleware"
Expand Down Expand Up @@ -104,21 +104,15 @@ func Server(keyFunc jwt.Keyfunc, opts ...Option) middleware.Middleware {
tokenInfo, err = jwt.Parse(jwtToken, keyFunc)
}
if err != nil {
ve, ok := err.(*jwt.ValidationError)
if !ok {
return nil, errors.Unauthorized(reason, err.Error())
}
if ve.Errors&jwt.ValidationErrorMalformed != 0 {
if errors.Is(err, jwt.ErrTokenMalformed) || errors.Is(err, jwt.ErrTokenUnverifiable) {
return nil, ErrTokenInvalid
}
if ve.Errors&(jwt.ValidationErrorExpired|jwt.ValidationErrorNotValidYet) != 0 {
if errors.Is(err, jwt.ErrTokenNotValidYet) || errors.Is(err, jwt.ErrTokenExpired) {
return nil, ErrTokenExpired
}
if ve.Inner != nil {
return nil, ve.Inner
}
return nil, ErrTokenParseFail
}

if !tokenInfo.Valid {
return nil, ErrTokenInvalid
}
Expand Down
2 changes: 1 addition & 1 deletion middleware/auth/jwt/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"testing"
"time"

"github.com/golang-jwt/jwt/v4"
"github.com/golang-jwt/jwt/v5"

"github.com/go-kratos/kratos/v2/middleware"
"github.com/go-kratos/kratos/v2/transport"
Expand Down

0 comments on commit 7e2edec

Please sign in to comment.