Skip to content

Commit d3d2ecb

Browse files
committed
server: upgrade jwt dependecy
1 parent d8c890c commit d3d2ecb

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.23.0
55
toolchain go1.24.2
66

77
require (
8-
github.com/golang-jwt/jwt v3.2.2+incompatible
8+
github.com/golang-jwt/jwt/v4 v4.5.2
99
github.com/jmoiron/sqlx v1.3.5
1010
github.com/kelseyhightower/envconfig v1.4.0
1111
github.com/labstack/echo/v4 v4.10.2
@@ -17,6 +17,7 @@ require (
1717

1818
require (
1919
github.com/davecgh/go-spew v1.1.1 // indirect
20+
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
2021
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
2122
github.com/kr/text v0.2.0 // indirect
2223
github.com/mattn/go-colorable v0.1.13 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfC
88
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
99
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
1010
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
11+
github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXeUI=
12+
github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
1113
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
1214
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
1315
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=

server/auth.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"net/http"
66
"time"
77

8-
"github.com/golang-jwt/jwt"
8+
"github.com/golang-jwt/jwt/v4"
99
"github.com/labstack/echo/v4"
1010
"github.com/labstack/echo/v4/middleware"
1111
"github.com/mrdoob/glsl-sandbox/server/store"
@@ -18,12 +18,10 @@ const (
1818
bcryptCost = 8
1919
)
2020

21-
var (
22-
ErrNotAuthorized = fmt.Errorf("user not authorized")
23-
)
21+
var ErrNotAuthorized = fmt.Errorf("user not authorized")
2422

2523
type Claims struct {
26-
jwt.StandardClaims
24+
jwt.RegisteredClaims
2725

2826
Name string `json:"name"`
2927
Role store.Role `json:"role"`
@@ -49,12 +47,12 @@ func (a *Auth) GenerateToken(c echo.Context, u store.User) error {
4947
return fmt.Errorf("invalid role")
5048
}
5149

52-
expirationTime := time.Now().Add(tokenDuration)
50+
expirationTime := jwt.NewNumericDate(time.Now().Add(tokenDuration))
5351
claims := Claims{
5452
Name: u.Name,
5553
Role: u.Role,
56-
StandardClaims: jwt.StandardClaims{
57-
ExpiresAt: expirationTime.Unix(),
54+
RegisteredClaims: jwt.RegisteredClaims{
55+
ExpiresAt: expirationTime,
5856
},
5957
}
6058

@@ -68,7 +66,7 @@ func (a *Auth) GenerateToken(c echo.Context, u store.User) error {
6866
cookie := http.Cookie{
6967
Name: accessTokenCookieName,
7068
Value: tokenString,
71-
Expires: expirationTime,
69+
Expires: expirationTime.Time,
7270
Path: "/",
7371
HttpOnly: true,
7472
}

0 commit comments

Comments
 (0)