Skip to content

Commit 900ffdd

Browse files
authored
Merge branch 'master' into alovelltroy/add-jwks-support
2 parents 29975d0 + 21df586 commit 900ffdd

6 files changed

Lines changed: 71 additions & 68 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
strategy:
2222
matrix:
23-
go-version: [1.20.x, 1.21.x, 1.22.x]
23+
go-version: [1.22.x, 1.23.x, 1.24.x]
2424
os: [ubuntu-latest, macos-latest, windows-latest]
2525

2626
runs-on: ${{ matrix.os }}

_example/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ import (
6565

6666
"github.com/go-chi/chi/v5"
6767
"github.com/go-chi/jwtauth/v5"
68-
"github.com/lestrrat-go/jwx/v2/jwt"
68+
"github.com/lestrrat-go/jwx/v3/jwt"
6969
)
7070

7171
type dynamicTokenAuth struct {

go.mod

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ toolchain go1.24.2
66

77
require (
88
github.com/go-chi/chi/v5 v5.2.1
9-
github.com/lestrrat-go/jwx/v2 v2.1.4
9+
github.com/lestrrat-go/jwx/v3 v3.0.2
1010
)
1111

1212
require (
1313
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
1414
github.com/goccy/go-json v0.10.3 // indirect
15-
github.com/lestrrat-go/blackmagic v1.0.2 // indirect
15+
github.com/lestrrat-go/blackmagic v1.0.3 // indirect
1616
github.com/lestrrat-go/httpcc v1.0.1 // indirect
17-
github.com/lestrrat-go/httprc v1.0.6 // indirect
18-
github.com/lestrrat-go/iter v1.0.2 // indirect
17+
github.com/lestrrat-go/httprc/v3 v3.0.0-beta2 // indirect
1918
github.com/lestrrat-go/option v1.0.1 // indirect
2019
github.com/segmentio/asm v1.2.0 // indirect
21-
golang.org/x/crypto v0.37.0 // indirect
22-
golang.org/x/sys v0.32.0 // indirect
20+
golang.org/x/crypto v0.38.0 // indirect
21+
golang.org/x/sys v0.33.0 // indirect
2322
)

go.sum

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ github.com/go-chi/chi/v5 v5.2.1 h1:KOIHODQj58PmL80G2Eak4WdvUzjSJSm0vG72crDCqb8=
77
github.com/go-chi/chi/v5 v5.2.1/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
88
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
99
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
10-
github.com/lestrrat-go/blackmagic v1.0.2 h1:Cg2gVSc9h7sz9NOByczrbUvLopQmXrfFx//N+AkAr5k=
11-
github.com/lestrrat-go/blackmagic v1.0.2/go.mod h1:UrEqBzIR2U6CnzVyUtfM6oZNMt/7O7Vohk2J0OGSAtU=
10+
github.com/lestrrat-go/blackmagic v1.0.3 h1:94HXkVLxkZO9vJI/w2u1T0DAoprShFd13xtnSINtDWs=
11+
github.com/lestrrat-go/blackmagic v1.0.3/go.mod h1:6AWFyKNNj0zEXQYfTMPfZrAXUWUfTIZ5ECEUEJaijtw=
1212
github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE=
1313
github.com/lestrrat-go/httpcc v1.0.1/go.mod h1:qiltp3Mt56+55GPVCbTdM9MlqhvzyuL6W/NMDA8vA5E=
14-
github.com/lestrrat-go/httprc v1.0.6 h1:qgmgIRhpvBqexMJjA/PmwSvhNk679oqD1RbovdCGW8k=
15-
github.com/lestrrat-go/httprc v1.0.6/go.mod h1:mwwz3JMTPBjHUkkDv/IGJ39aALInZLrhBp0X7KGUZlo=
16-
github.com/lestrrat-go/iter v1.0.2 h1:gMXo1q4c2pHmC3dn8LzRhJfP1ceCbgSiT9lUydIzltI=
17-
github.com/lestrrat-go/iter v1.0.2/go.mod h1:Momfcq3AnRlRjI5b5O8/G5/BvpzrhoFTZcn06fEOPt4=
18-
github.com/lestrrat-go/jwx/v2 v2.1.4 h1:uBCMmJX8oRZStmKuMMOFb0Yh9xmEMgNJLgjuKKt4/qc=
19-
github.com/lestrrat-go/jwx/v2 v2.1.4/go.mod h1:nWRbDFR1ALG2Z6GJbBXzfQaYyvn751KuuyySN2yR6is=
14+
github.com/lestrrat-go/httprc/v3 v3.0.0-beta2 h1:SDxjGoH7qj0nBXVrcrxX8eD94wEnjR+EEuqqmeqQYlY=
15+
github.com/lestrrat-go/httprc/v3 v3.0.0-beta2/go.mod h1:Nwo81sMxE0DcvTB+rJyynNhv/DUu2yZErV7sscw9pHE=
16+
github.com/lestrrat-go/jwx/v3 v3.0.2 h1:N+XLjTJEzDZRP3S0SezclXFAfopwL+o5vaL+qg6rX1I=
17+
github.com/lestrrat-go/jwx/v3 v3.0.2/go.mod h1:qO9w1qkQH77a0r9OXNM33YQPnV/evetKYRg58h1rBNE=
2018
github.com/lestrrat-go/option v1.0.1 h1:oAzP2fvZGQKWkvHa1/SAcFolBEca1oN+mQ7eooNBEYU=
2119
github.com/lestrrat-go/option v1.0.1/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I=
2220
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -28,10 +26,10 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
2826
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
2927
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
3028
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
31-
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
32-
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
33-
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
34-
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
29+
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8=
30+
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
31+
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
32+
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
3533
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
3634
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
3735
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

jwtauth.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import (
88
"strings"
99
"time"
1010

11-
"github.com/lestrrat-go/jwx/v2/jwa"
12-
"github.com/lestrrat-go/jwx/v2/jwk"
13-
"github.com/lestrrat-go/jwx/v2/jwt"
11+
"github.com/lestrrat-go/jwx/v3/jwa"
12+
"github.com/lestrrat-go/jwx/v3/jwk"
13+
"github.com/lestrrat-go/jwx/v3/jwt"
14+
"github.com/lestrrat-go/jwx/v3/transform"
1415
)
1516

1617
type JWTAuth struct {
@@ -37,8 +38,9 @@ var (
3738
)
3839

3940
func New(alg string, signKey interface{}, verifyKey interface{}, validateOptions ...jwt.ValidateOption) *JWTAuth {
41+
sigAlg, _ := jwa.LookupSignatureAlgorithm(alg)
4042
ja := &JWTAuth{
41-
alg: jwa.SignatureAlgorithm(alg),
43+
alg: sigAlg,
4244
signKey: signKey,
4345
verifyKey: verifyKey,
4446
validateOptions: validateOptions,
@@ -184,11 +186,11 @@ func (ja *JWTAuth) parse(payload []byte) (jwt.Token, error) {
184186
// jwt library
185187
func ErrorReason(err error) error {
186188
switch {
187-
case errors.Is(err, jwt.ErrTokenExpired()), err == ErrExpired:
189+
case errors.Is(err, jwt.TokenExpiredError()), err == ErrExpired:
188190
return ErrExpired
189-
case errors.Is(err, jwt.ErrInvalidIssuedAt()), err == ErrIATInvalid:
191+
case errors.Is(err, jwt.InvalidIssuedAtError()), err == ErrIATInvalid:
190192
return ErrIATInvalid
191-
case errors.Is(err, jwt.ErrTokenNotYetValid()), err == ErrNBFInvalid:
193+
case errors.Is(err, jwt.TokenNotYetValidError()), err == ErrNBFInvalid:
192194
return ErrNBFInvalid
193195
default:
194196
return ErrUnauthorized
@@ -231,15 +233,11 @@ func FromContext(ctx context.Context) (jwt.Token, map[string]interface{}, error)
231233
token, _ := ctx.Value(TokenCtxKey).(jwt.Token)
232234

233235
var err error
234-
var claims map[string]interface{}
235-
236+
claims := map[string]interface{}{}
236237
if token != nil {
237-
claims, err = token.AsMap(context.Background())
238-
if err != nil {
238+
if err = transform.AsMap(token, claims); err != nil {
239239
return token, nil, err
240240
}
241-
} else {
242-
claims = map[string]interface{}{}
243241
}
244242

245243
err, _ = ctx.Value(ErrorCtxKey).(error)

jwtauth_test.go

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package jwtauth_test
22

33
import (
4-
"context"
54
"crypto/x509"
65
"encoding/pem"
76
"fmt"
@@ -17,8 +16,9 @@ import (
1716

1817
"github.com/go-chi/chi/v5"
1918
"github.com/go-chi/jwtauth/v5"
20-
"github.com/lestrrat-go/jwx/v2/jwa"
21-
"github.com/lestrrat-go/jwx/v2/jwt"
19+
"github.com/lestrrat-go/jwx/v3/jwa"
20+
"github.com/lestrrat-go/jwx/v3/jwt"
21+
"github.com/lestrrat-go/jwx/v3/transform"
2222
)
2323

2424
var (
@@ -28,19 +28,27 @@ var (
2828
TokenAuthRS256 *jwtauth.JWTAuth
2929

3030
PrivateKeyRS256String = `-----BEGIN RSA PRIVATE KEY-----
31-
MIIBOwIBAAJBALxo3PCjFw4QjgOX06QCJIJBnXXNiEYwDLxxa5/7QyH6y77nCRQy
32-
J3x3UwF9rUD0RCsp4sNdX5kOQ9PUyHyOtCUCAwEAAQJARjFLHtuj2zmPrwcBcjja
33-
IS0Q3LKV8pA0LoCS+CdD+4QwCxeKFq0yEMZtMvcQOfqo9x9oAywFClMSlLRyl7ng
34-
gQIhAOyerGbcdQxxwjwGpLS61Mprf4n2HzjwISg20cEEH1tfAiEAy9dXmgQpDPir
35-
C6Q9QdLXpNgSB+o5CDqfor7TTyTCovsCIQDNCfpu795luDYN+dvD2JoIBfrwu9v2
36-
ZO72f/pm/YGGlQIgUdRXyW9kH13wJFNBeBwxD27iBiVj0cbe8NFUONBUBmMCIQCN
37-
jVK4eujt1lm/m60TlEhaWBC3p+3aPT2TqFPUigJ3RQ==
31+
MIICXgIBAAKBgQDsH6T+WrdRLKHEhbhbnItRo7X5tj0xssOSCJUiZbCHr52XftIr
32+
hBD6HxbGaKUEzuaCDYGEcQZZRJ1KHfYmJtXPCz4Zp3qlhjNugvTaZoFtQ8RqiWVY
33+
cHqCY6cmI+3cq2mVrd7MstpXKhC8dZ2MZnzx/zqaeiV21SiwxHed8LmWmQIDAQAB
34+
AoGAff9I0L1hkrxJOg/M133KTe8Y3L4lG07z0wonYmp274CDjGKNDdF0KbPLOGaA
35+
n/czw3Qnh5+0LpBRikpAng0dC06z0YnyzrkoPPawC4s2zJeY3NnajK9IfRAAVlby
36+
cIJVmEL/xF3FFHhCfrJNWd+zthcHxCATJOBpH2pwhb4WLfECQQD/geZ/B6p8WlGb
37+
amHFhBd/hQN6cq63RGujf3ecz5H+h4RqFyycaVr3t8QZBBd3O3jRB9FCcan2IxRa
38+
UoYNGNB9AkEA7JQtfmb0p8cTHiDyV6qb8aNJFWipwQVVMmpaXvfC6Aue5uJiyHnx
39+
iScLsj1ozewCgTvzL7MAsfj0k6qX3c01TQJBAPL2JCdhM8XB4N4Hf+dhHzMcWd1j
40+
Fi6hOjWjrSsI2owNc2Wqmbo2GNF8BlW/ZUz02YLzixJCoVqzqtPkqyHjGcUCQQDk
41+
msrbOeFvvo5arrt+uv21oXMdnOVr/xs0fFCXNBLC53fE4z1RO4SKY5CJy41abpR9
42+
DNERZodlcovjpRTa31CBAkEAw8geqJ1+cfEDZYfJxJigFSwbwoLw6BH+GD4KAEdX
43+
G1u9SGGYP19eC2mpQei4V5MqAYEbb82bqcebhwg8kAReNQ==
3844
-----END RSA PRIVATE KEY-----
3945
`
4046

4147
PublicKeyRS256String = `-----BEGIN PUBLIC KEY-----
42-
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALxo3PCjFw4QjgOX06QCJIJBnXXNiEYw
43-
DLxxa5/7QyH6y77nCRQyJ3x3UwF9rUD0RCsp4sNdX5kOQ9PUyHyOtCUCAwEAAQ==
48+
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDsH6T+WrdRLKHEhbhbnItRo7X5
49+
tj0xssOSCJUiZbCHr52XftIrhBD6HxbGaKUEzuaCDYGEcQZZRJ1KHfYmJtXPCz4Z
50+
p3qlhjNugvTaZoFtQ8RqiWVYcHqCY6cmI+3cq2mVrd7MstpXKhC8dZ2MZnzx/zqa
51+
eiV21SiwxHed8LmWmQIDAQAB
4452
-----END PUBLIC KEY-----
4553
`
4654

@@ -67,7 +75,7 @@ DLxxa5/7QyH6y77nCRQyJ3x3UwF9rUD0RCsp4sNdX5kOQ9PUyHyOtCUCAwEAAQ==
6775
)
6876

6977
func init() {
70-
TokenAuthHS256 = jwtauth.New(jwa.HS256.String(), TokenSecret, nil, jwt.WithAcceptableSkew(30*time.Second))
78+
TokenAuthHS256 = jwtauth.New(jwa.HS256().String(), TokenSecret, nil, jwt.WithAcceptableSkew(30*time.Second))
7179
}
7280

7381
//
@@ -181,17 +189,17 @@ func TestSimpleRSA(t *testing.T) {
181189

182190
privateKey, err := x509.ParsePKCS1PrivateKey(privateKeyBlock.Bytes)
183191
if err != nil {
184-
t.Fatalf(err.Error())
192+
t.Fatal(err.Error())
185193
}
186194

187195
publicKeyBlock, _ := pem.Decode([]byte(PublicKeyRS256String))
188196

189197
publicKey, err := x509.ParsePKIXPublicKey(publicKeyBlock.Bytes)
190198
if err != nil {
191-
t.Fatalf(err.Error())
199+
t.Fatal(err.Error())
192200
}
193201

194-
TokenAuthRS256 = jwtauth.New(jwa.RS256.String(), privateKey, publicKey)
202+
TokenAuthRS256 = jwtauth.New(jwa.RS256().String(), privateKey, publicKey)
195203

196204
claims := map[string]interface{}{
197205
"key": "val",
@@ -209,9 +217,9 @@ func TestSimpleRSA(t *testing.T) {
209217
t.Fatalf("Failed to decode token string %s\n", err.Error())
210218
}
211219

212-
tokenClaims, err := token.AsMap(context.Background())
213-
if err != nil {
214-
t.Fatal(err.Error())
220+
tokenClaims := map[string]interface{}{}
221+
if err := transform.AsMap(token, tokenClaims); err != nil {
222+
t.Fatalf("Failed to get claims %s\n", err.Error())
215223
}
216224

217225
if !reflect.DeepEqual(claims, tokenClaims) {
@@ -220,7 +228,7 @@ func TestSimpleRSA(t *testing.T) {
220228
}
221229

222230
func TestSimpleRSAVerifyOnly(t *testing.T) {
223-
tokenString := "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ2YWwiLCJrZXkyIjoidmFsMiIsImtleTMiOiJ2YWwzIn0.kLEK3FZZPsAlQNKR5yHyjRyrlCJFhvKmrh7o-GqDT_zaGQgvb0Dufp8uNSMeOFAlLGK5FbKX7BckjJqfvEyrTQ"
231+
tokenString := "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ2YWwiLCJrZXkyIjoidmFsMiIsImtleTMiOiJ2YWwzIn0.IK0G0Qi_c6N6uHRokHMSHQEeYxoi_T73A4RdEzJIfnbs5kA5hF0UhApSWUMZfsTYFNC2buYvWqbyj2kDdXcStpqTUPENGTKvJi66puwhN16BqEOS-jb7kVyf3vWif7XabY0_5S8H_aeqazaj4FemHvWnywJznuMWJRXWw83edpA"
224232
claims := map[string]interface{}{
225233
"key": "val",
226234
"key2": "val2",
@@ -230,10 +238,10 @@ func TestSimpleRSAVerifyOnly(t *testing.T) {
230238
publicKeyBlock, _ := pem.Decode([]byte(PublicKeyRS256String))
231239
publicKey, err := x509.ParsePKIXPublicKey(publicKeyBlock.Bytes)
232240
if err != nil {
233-
t.Fatalf(err.Error())
241+
t.Fatal(err.Error())
234242
}
235243

236-
TokenAuthRS256 = jwtauth.New(jwa.RS256.String(), nil, publicKey)
244+
TokenAuthRS256 = jwtauth.New(jwa.RS256().String(), nil, publicKey)
237245

238246
_, _, err = TokenAuthRS256.Encode(claims)
239247
if err == nil {
@@ -245,9 +253,9 @@ func TestSimpleRSAVerifyOnly(t *testing.T) {
245253
t.Fatalf("Failed to decode token string %s\n", err.Error())
246254
}
247255

248-
tokenClaims, err := token.AsMap(context.Background())
249-
if err != nil {
250-
t.Fatal(err.Error())
256+
tokenClaims := map[string]interface{}{}
257+
if err := transform.AsMap(token, tokenClaims); err != nil {
258+
t.Fatalf("Failed to get claims %s\n", err.Error())
251259
}
252260

253261
if !reflect.DeepEqual(claims, tokenClaims) {
@@ -306,42 +314,42 @@ func TestMore(t *testing.T) {
306314

307315
// sending unauthorized requests
308316
if status, resp := testRequest(t, ts, "GET", "/admin", nil, nil); status != 401 || resp != "token is unauthorized\n" {
309-
t.Fatalf(resp)
317+
t.Fatal(resp)
310318
}
311319

312320
h := http.Header{}
313321
h.Set("Authorization", "BEARER "+newJwtToken([]byte("wrong"), map[string]interface{}{}))
314322
if status, resp := testRequest(t, ts, "GET", "/admin", h, nil); status != 401 || resp != "token is unauthorized\n" {
315-
t.Fatalf(resp)
323+
t.Fatal(resp)
316324
}
317325
h.Set("Authorization", "BEARER asdf")
318326
if status, resp := testRequest(t, ts, "GET", "/admin", h, nil); status != 401 || resp != "token is unauthorized\n" {
319-
t.Fatalf(resp)
327+
t.Fatal(resp)
320328
}
321329
// wrong token secret and wrong alg
322330
h.Set("Authorization", "BEARER "+newJwt512Token([]byte("wrong"), map[string]interface{}{}))
323331
if status, resp := testRequest(t, ts, "GET", "/admin", h, nil); status != 401 || resp != "token is unauthorized\n" {
324-
t.Fatalf(resp)
332+
t.Fatal(resp)
325333
}
326334
// correct token secret but wrong alg
327335
h.Set("Authorization", "BEARER "+newJwt512Token(TokenSecret, map[string]interface{}{}))
328336
if status, resp := testRequest(t, ts, "GET", "/admin", h, nil); status != 401 || resp != "token is unauthorized\n" {
329-
t.Fatalf(resp)
337+
t.Fatal(resp)
330338
}
331339

332340
h = newAuthHeader(map[string]interface{}{"exp": jwtauth.EpochNow() - 1000})
333341
if status, resp := testRequest(t, ts, "GET", "/admin", h, nil); status != 401 || resp != "token is expired\n" {
334-
t.Fatalf(resp)
342+
t.Fatal(resp)
335343
}
336344

337345
// sending authorized requests
338346
if status, resp := testRequest(t, ts, "GET", "/", nil, nil); status != 200 || resp != "welcome" {
339-
t.Fatalf(resp)
347+
t.Fatal(resp)
340348
}
341349

342350
h = newAuthHeader((map[string]interface{}{"user_id": 31337, "exp": jwtauth.ExpireIn(5 * time.Minute)}))
343351
if status, resp := testRequest(t, ts, "GET", "/admin", h, nil); status != 200 || resp != "protected, user:31337" {
344-
t.Fatalf(resp)
352+
t.Fatal(resp)
345353
}
346354
}
347355

@@ -499,7 +507,7 @@ func newJwtToken(secret []byte, claims ...map[string]interface{}) string {
499507
}
500508
}
501509

502-
tokenPayload, err := jwt.Sign(token, jwt.WithKey(jwa.HS256, secret))
510+
tokenPayload, err := jwt.Sign(token, jwt.WithKey(jwa.HS256(), secret))
503511
if err != nil {
504512
log.Fatal(err)
505513
}
@@ -514,7 +522,7 @@ func newJwt512Token(secret []byte, claims ...map[string]interface{}) string {
514522
token.Set(k, v)
515523
}
516524
}
517-
tokenPayload, err := jwt.Sign(token, jwt.WithKey(jwa.HS512, secret))
525+
tokenPayload, err := jwt.Sign(token, jwt.WithKey(jwa.HS512(), secret))
518526
if err != nil {
519527
log.Fatal(err)
520528
}

0 commit comments

Comments
 (0)