build(go): use jwt/v5

This commit is contained in:
sshakndr
2025-08-01 13:42:53 +07:00
parent 01786b3059
commit 564a077cdb
14 changed files with 52 additions and 52 deletions

View File

@ -3,7 +3,7 @@ module github.com/ONLYOFFICE/document-server-integration
go 1.21
require (
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/golang-jwt/jwt/v5 v5.3.0
github.com/gorilla/mux v1.8.1
github.com/gorilla/schema v1.4.1
github.com/mitchellh/mapstructure v1.5.0

View File

@ -6,8 +6,8 @@ github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHk
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang-jwt/jwt/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9vvo=
github.com/golang-jwt/jwt/v5 v5.3.0/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=

View File

@ -27,7 +27,7 @@ import (
"github.com/ONLYOFFICE/document-server-integration/server/managers"
"github.com/ONLYOFFICE/document-server-integration/server/models"
"github.com/ONLYOFFICE/document-server-integration/server/shared"
"github.com/golang-jwt/jwt"
"github.com/golang-jwt/jwt/v5"
)
func (srv *DefaultServerEndpointsHandler) Config(w http.ResponseWriter, r *http.Request) {
@ -73,9 +73,9 @@ func (srv *DefaultServerEndpointsHandler) Config(w http.ResponseWriter, r *http.
),
Mode: "edit",
},
StandardClaims: jwt.StandardClaims{
ExpiresAt: time.Now().Add(time.Minute * srv.config.JwtExpiresIn).Unix(),
IssuedAt: time.Now().Unix(),
RegisteredClaims: jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * srv.config.JwtExpiresIn)),
IssuedAt: jwt.NewNumericDate(time.Now()),
},
}

View File

@ -29,7 +29,7 @@ import (
"github.com/ONLYOFFICE/document-server-integration/server/models"
"github.com/ONLYOFFICE/document-server-integration/server/shared"
"github.com/ONLYOFFICE/document-server-integration/utils"
"github.com/golang-jwt/jwt"
"github.com/golang-jwt/jwt/v5"
)
func (srv *DefaultServerEndpointsHandler) Reference(w http.ResponseWriter, r *http.Request) {
@ -97,9 +97,9 @@ func (srv *DefaultServerEndpointsHandler) Reference(w http.ResponseWriter, r *ht
},
Link: remoteAddr + "/editor?filename=" + url.QueryEscape(fileName),
Path: fileName,
StandardClaims: jwt.StandardClaims{
ExpiresAt: time.Now().Add(time.Minute * srv.config.JwtExpiresIn).Unix(),
IssuedAt: time.Now().Unix(),
RegisteredClaims: jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * srv.config.JwtExpiresIn)),
IssuedAt: jwt.NewNumericDate(time.Now()),
},
}

View File

@ -22,7 +22,7 @@ import (
"net/http"
"github.com/ONLYOFFICE/document-server-integration/server/models"
"github.com/golang-jwt/jwt"
"github.com/golang-jwt/jwt/v5"
)
type DocumentManager interface {

View File

@ -27,7 +27,7 @@ import (
"github.com/ONLYOFFICE/document-server-integration/config"
"github.com/ONLYOFFICE/document-server-integration/server/managers"
"github.com/golang-jwt/jwt"
"github.com/golang-jwt/jwt/v5"
)
type DefaultCommandManager struct {
@ -40,13 +40,13 @@ type CommandPayload struct {
Key string `json:"key"`
Meta interface{} `json:"meta"`
Token string `json:"token"`
jwt.StandardClaims
jwt.RegisteredClaims
}
type CommandRequestHeaderPayload struct {
Query map[string]string `json:"query"`
Payload CommandPayload `json:"payload"`
jwt.StandardClaims
jwt.RegisteredClaims
}
func NewDefaultCommandManager(config config.ApplicationConfig, jmanager managers.JwtManager) managers.CommandManager {
@ -60,9 +60,9 @@ func (cm DefaultCommandManager) CommandRequest(method string, docKey string, met
payload := CommandPayload{
C: method,
Key: docKey,
StandardClaims: jwt.StandardClaims{
ExpiresAt: time.Now().Add(time.Minute * cm.config.JwtExpiresIn).Unix(),
IssuedAt: time.Now().Unix(),
RegisteredClaims: jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * cm.config.JwtExpiresIn)),
IssuedAt: jwt.NewNumericDate(time.Now()),
},
}
if meta != nil {
@ -119,9 +119,9 @@ func fillJwtByUrl(uri string, payload CommandPayload, config config.ApplicationC
return CommandRequestHeaderPayload{
Query: queryMap,
Payload: payload,
StandardClaims: jwt.StandardClaims{
ExpiresAt: time.Now().Add(time.Minute * config.JwtExpiresIn).Unix(),
IssuedAt: time.Now().Unix(),
RegisteredClaims: jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * config.JwtExpiresIn)),
IssuedAt: jwt.NewNumericDate(time.Now()),
},
}
}

View File

@ -30,7 +30,7 @@ import (
"github.com/ONLYOFFICE/document-server-integration/server/managers"
"github.com/ONLYOFFICE/document-server-integration/server/shared"
"github.com/ONLYOFFICE/document-server-integration/utils"
"github.com/golang-jwt/jwt"
"github.com/golang-jwt/jwt/v5"
"go.uber.org/zap"
)
@ -115,9 +115,9 @@ func (cm DefaultConversionManager) GetConverterUri(
Title: title,
Key: docKey,
Async: isAsync,
StandardClaims: jwt.StandardClaims{
ExpiresAt: time.Now().Add(time.Minute * cm.config.JwtExpiresIn).Unix(),
IssuedAt: time.Now().Unix(),
RegisteredClaims: jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * cm.config.JwtExpiresIn)),
IssuedAt: jwt.NewNumericDate(time.Now()),
},
}
@ -128,9 +128,9 @@ func (cm DefaultConversionManager) GetConverterUri(
if secret != "" && cm.config.JwtEnabled {
headerPayload := managers.ConvertRequestHeaderPayload{
Payload: payload,
StandardClaims: jwt.StandardClaims{
ExpiresAt: time.Now().Add(time.Minute * cm.config.JwtExpiresIn).Unix(),
IssuedAt: time.Now().Unix(),
RegisteredClaims: jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * cm.config.JwtExpiresIn)),
IssuedAt: jwt.NewNumericDate(time.Now()),
},
}
headerToken, err = cm.JwtManager.JwtSign(headerPayload, []byte(secret))

View File

@ -28,7 +28,7 @@ import (
"github.com/ONLYOFFICE/document-server-integration/server/managers"
"github.com/ONLYOFFICE/document-server-integration/server/models"
"github.com/ONLYOFFICE/document-server-integration/utils"
"github.com/golang-jwt/jwt"
"github.com/golang-jwt/jwt/v5"
"go.uber.org/zap"
)
@ -227,9 +227,9 @@ func (dm DefaultDocumentManager) BuildDocumentConfig(
},
},
},
StandardClaims: jwt.StandardClaims{
ExpiresAt: time.Now().Add(time.Minute * dm.config.JwtExpiresIn).Unix(),
IssuedAt: time.Now().Unix(),
RegisteredClaims: jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * dm.config.JwtExpiresIn)),
IssuedAt: jwt.NewNumericDate(time.Now()),
},
}

View File

@ -30,7 +30,7 @@ import (
"github.com/ONLYOFFICE/document-server-integration/server/models"
"github.com/ONLYOFFICE/document-server-integration/server/shared"
"github.com/ONLYOFFICE/document-server-integration/utils"
"github.com/golang-jwt/jwt"
"github.com/golang-jwt/jwt/v5"
"go.uber.org/zap"
)
@ -197,9 +197,9 @@ func (hm DefaultHistoryManager) fetchNextHistoryEntry(
Key: key,
Url: url,
Version: version,
StandardClaims: jwt.StandardClaims{
ExpiresAt: time.Now().Add(time.Minute * hm.config.JwtExpiresIn).Unix(),
IssuedAt: time.Now().Unix(),
RegisteredClaims: jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * hm.config.JwtExpiresIn)),
IssuedAt: jwt.NewNumericDate(time.Now()),
},
}
}
@ -267,9 +267,9 @@ func (hm DefaultHistoryManager) GetHistory(
Url: hm.StorageManager.GeneratePublicFileUri(filename, remoteAddress, managers.FileMeta{}),
Version: version,
ChangesUrl: changesUrl,
StandardClaims: jwt.StandardClaims{
ExpiresAt: time.Now().Add(time.Minute * hm.config.JwtExpiresIn).Unix(),
IssuedAt: time.Now().Unix(),
RegisteredClaims: jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * hm.config.JwtExpiresIn)),
IssuedAt: jwt.NewNumericDate(time.Now()),
},
}

View File

@ -24,7 +24,7 @@ import (
"github.com/ONLYOFFICE/document-server-integration/config"
"github.com/ONLYOFFICE/document-server-integration/server/managers"
"github.com/ONLYOFFICE/document-server-integration/server/models"
"github.com/golang-jwt/jwt"
"github.com/golang-jwt/jwt/v5"
"github.com/mitchellh/mapstructure"
"go.uber.org/zap"
)

View File

@ -21,7 +21,7 @@ import (
"errors"
"github.com/ONLYOFFICE/document-server-integration/server/models"
"github.com/golang-jwt/jwt"
"github.com/golang-jwt/jwt/v5"
)
var ErrInvalidFilename = errors.New("invalid filename")
@ -39,7 +39,7 @@ type HistorySet struct {
Url string `json:"url"`
Version int `json:"version"`
Token string `json:"token,omitempty"`
jwt.StandardClaims
jwt.RegisteredClaims
}
type HistoryPrevious struct {
@ -99,10 +99,10 @@ type ConvertRequestPayload struct {
Key string `json:"key"`
Async bool `json:"async"`
JwtToken string `json:"token,omitempty"`
jwt.StandardClaims
jwt.RegisteredClaims
}
type ConvertRequestHeaderPayload struct {
Payload ConvertRequestPayload `json:"payload"`
jwt.StandardClaims
jwt.RegisteredClaims
}

View File

@ -17,7 +17,7 @@
*/
package models
import "github.com/golang-jwt/jwt"
import "github.com/golang-jwt/jwt/v5"
type Command int
@ -38,9 +38,9 @@ func (c Command) Ordinal() int {
}
type CommandBody struct {
Command string `json:"c"`
Token string `json:"token,omitempty"`
jwt.StandardClaims `json:"-"`
Command string `json:"c"`
Token string `json:"token,omitempty"`
jwt.RegisteredClaims `json:"-"`
}
type CommandResponse struct {

View File

@ -17,7 +17,7 @@
*/
package models
import "github.com/golang-jwt/jwt"
import "github.com/golang-jwt/jwt/v5"
type Config struct {
Type string `json:"type"`
@ -25,5 +25,5 @@ type Config struct {
DocumentType string `json:"documentType"`
EditorConfig EditorConfig `json:"editorConfig"`
Token string `json:"token,omitempty"`
jwt.StandardClaims
jwt.RegisteredClaims
}

View File

@ -17,7 +17,7 @@
*/
package models
import "github.com/golang-jwt/jwt"
import "github.com/golang-jwt/jwt/v5"
type ReferenceData struct {
FileKey string `json:"fileKey"`
@ -32,5 +32,5 @@ type Reference struct {
Key string `json:"key"`
Url string `json:"url"`
Token string `json:"token,omitempty"`
jwt.StandardClaims
jwt.RegisteredClaims
}