Skip to content

Commit 6944ffe

Browse files
authored
Jwt v5 update (#9)
Jwt v5 update
1 parent 95b0b60 commit 6944ffe

File tree

9 files changed

+19
-21
lines changed

9 files changed

+19
-21
lines changed

.github/workflows/checks.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ permissions:
1414

1515
env:
1616
# run static analysis only with the latest Go version
17-
LATEST_GO_VERSION: 1.19
17+
LATEST_GO_VERSION: "1.20"
1818

1919
jobs:
2020
check:
@@ -44,5 +44,3 @@ jobs:
4444
go version
4545
go install golang.org/x/vuln/cmd/govulncheck@latest
4646
govulncheck ./...
47-
48-

.github/workflows/echo.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
# Echo tests with last four major releases (unless there are pressing vulnerabilities)
2626
# As we depend on `golang.org/x/` libraries which only support last 2 Go releases we could have situations when
2727
# we derive from last four major releases promise.
28-
go: [1.17, 1.18, 1.19]
28+
go: ["1.18", "1.19", "1.20"]
2929
name: ${{ matrix.os }} @ Go ${{ matrix.go }}
3030
runs-on: ${{ matrix.os }}
3131
steps:

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# Echo JWT middleware
88

9-
JWT middleware for [Echo](https://github.com/labstack/echo) framework. This middleware uses by default [golang-jwt/jwt/v4](https://github.com/golang-jwt/jwt)
9+
JWT middleware for [Echo](https://github.com/labstack/echo) framework. This middleware uses by default [golang-jwt/jwt/v5](https://github.com/golang-jwt/jwt)
1010
as JWT implementation.
1111

1212
## Versioning
@@ -48,7 +48,7 @@ e.Use(echojwt.WithConfig(echojwt.Config{
4848

4949
Extract token in handler
5050
```go
51-
import "github.com/golang-jwt/jwt/v4"
51+
import "github.com/golang-jwt/jwt/v5"
5252

5353
// ...
5454

@@ -72,7 +72,7 @@ package main
7272

7373
import (
7474
"errors"
75-
"github.com/golang-jwt/jwt/v4"
75+
"github.com/golang-jwt/jwt/v5"
7676
"github.com/labstack/echo-jwt/v4"
7777
"github.com/labstack/echo/v4"
7878
"github.com/labstack/echo/v4/middleware"

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/labstack/echo-jwt/v4
33
go 1.17
44

55
require (
6-
github.com/golang-jwt/jwt/v4 v4.4.3
6+
github.com/golang-jwt/jwt/v5 v5.0.0
77
github.com/labstack/echo/v4 v4.9.0
88
github.com/stretchr/testify v1.8.1
99
)

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
33
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
44
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
55
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
6-
github.com/golang-jwt/jwt/v4 v4.4.3 h1:Hxl6lhQFj4AnOX6MLrsCb/+7tCj7DxP7VA+2rDIq5AU=
7-
github.com/golang-jwt/jwt/v4 v4.4.3/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
6+
github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE=
7+
github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
88
github.com/labstack/echo/v4 v4.9.0 h1:wPOF1CE6gvt/kmbMR4dGzWvHMPT+sAEUJOwOTtvITVY=
99
github.com/labstack/echo/v4 v4.9.0/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks=
1010
github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=

jwt.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"fmt"
99
"net/http"
1010

11-
"github.com/golang-jwt/jwt/v4"
11+
"github.com/golang-jwt/jwt/v5"
1212
"github.com/labstack/echo/v4"
1313
"github.com/labstack/echo/v4/middleware"
1414
)

jwt_benchmark_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package echojwt
22

33
import (
4-
"github.com/golang-jwt/jwt/v4"
4+
"github.com/golang-jwt/jwt/v5"
55
"github.com/labstack/echo/v4"
66
"net/http"
77
"net/http/httptest"

jwt_extranal_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package echojwt_test
66
import (
77
"errors"
88
"fmt"
9-
"github.com/golang-jwt/jwt/v4"
9+
"github.com/golang-jwt/jwt/v5"
1010
echojwt "github.com/labstack/echo-jwt/v4"
1111
"github.com/labstack/echo/v4"
1212
"io"
@@ -25,7 +25,7 @@ func ExampleWithConfig_usage() {
2525

2626
e.GET("/", func(c echo.Context) error {
2727
// make sure that your imports are correct versions. for example if you use `"github.com/golang-jwt/jwt"` as
28-
// import this cast will fail and `"github.com/golang-jwt/jwt/v4"` will succeed.
28+
// import this cast will fail and `"github.com/golang-jwt/jwt/v5"` will succeed.
2929
// Although `.(*jwt.Token)` looks exactly the same for both packages but this struct is still different
3030
token, ok := c.Get("user").(*jwt.Token) // by default token is stored under `user` key
3131
if !ok {

jwt_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"strings"
1313
"testing"
1414

15-
"github.com/golang-jwt/jwt/v4"
15+
"github.com/golang-jwt/jwt/v5"
1616
"github.com/labstack/echo/v4"
1717
"github.com/labstack/echo/v4/middleware"
1818
"github.com/stretchr/testify/assert"
@@ -110,15 +110,15 @@ func TestJWT_combinations(t *testing.T) {
110110
SigningKey: validKey,
111111
SigningMethod: "RS256",
112112
},
113-
expectError: "code=401, message=invalid or expired jwt, internal=unexpected jwt signing method=HS256",
113+
expectError: "code=401, message=invalid or expired jwt, internal=token is unverifiable: error while executing keyfunc: unexpected jwt signing method=HS256",
114114
},
115115
{
116116
name: "Invalid key",
117117
hdrAuth: validAuth,
118118
config: Config{
119119
SigningKey: invalidKey,
120120
},
121-
expectError: "code=401, message=invalid or expired jwt, internal=signature is invalid",
121+
expectError: "code=401, message=invalid or expired jwt, internal=token signature is invalid: signature is invalid",
122122
},
123123
{
124124
name: "Valid JWT",
@@ -189,7 +189,7 @@ func TestJWT_combinations(t *testing.T) {
189189
TokenLookup: "query:jwt",
190190
},
191191
reqURL: "/?a=b&jwt=invalid-token",
192-
expectError: "code=401, message=invalid or expired jwt, internal=token contains an invalid number of segments",
192+
expectError: "code=401, message=invalid or expired jwt, internal=token is malformed: token contains an invalid number of segments",
193193
},
194194
{
195195
name: "Empty query",
@@ -231,7 +231,7 @@ func TestJWT_combinations(t *testing.T) {
231231
TokenLookup: "cookie:jwt",
232232
},
233233
hdrCookie: "jwt=invalid",
234-
expectError: "code=401, message=invalid or expired jwt, internal=token contains an invalid number of segments",
234+
expectError: "code=401, message=invalid or expired jwt, internal=token is malformed: token contains an invalid number of segments",
235235
},
236236
{
237237
name: "Empty cookie",
@@ -256,7 +256,7 @@ func TestJWT_combinations(t *testing.T) {
256256
TokenLookup: "form:jwt",
257257
},
258258
formValues: map[string]string{"jwt": "invalid"},
259-
expectError: "code=401, message=invalid or expired jwt, internal=token contains an invalid number of segments",
259+
expectError: "code=401, message=invalid or expired jwt, internal=token is malformed: token contains an invalid number of segments",
260260
},
261261
{
262262
name: "Empty form field",
@@ -513,7 +513,7 @@ func TestConfig_ErrorHandling(t *testing.T) {
513513
},
514514
},
515515
whenAuthHeader: "Bearer x.x.x",
516-
expectError: "illegal base64 data at input byte 0",
516+
expectError: "token is malformed: could not base64 decode header: illegal base64 data at input byte 0",
517517
},
518518
}
519519

0 commit comments

Comments
 (0)