mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-04-07 14:06:11 +08:00
build(go): use jwt/v5
This commit is contained in:
@ -3,7 +3,7 @@ module github.com/ONLYOFFICE/document-server-integration
|
|||||||
go 1.21
|
go 1.21
|
||||||
|
|
||||||
require (
|
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/mux v1.8.1
|
||||||
github.com/gorilla/schema v1.4.1
|
github.com/gorilla/schema v1.4.1
|
||||||
github.com/mitchellh/mapstructure v1.5.0
|
github.com/mitchellh/mapstructure v1.5.0
|
||||||
|
|||||||
@ -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/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 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
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/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9vvo=
|
||||||
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
|
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 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
|
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
|
||||||
|
|||||||
@ -27,7 +27,7 @@ import (
|
|||||||
"github.com/ONLYOFFICE/document-server-integration/server/managers"
|
"github.com/ONLYOFFICE/document-server-integration/server/managers"
|
||||||
"github.com/ONLYOFFICE/document-server-integration/server/models"
|
"github.com/ONLYOFFICE/document-server-integration/server/models"
|
||||||
"github.com/ONLYOFFICE/document-server-integration/server/shared"
|
"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) {
|
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",
|
Mode: "edit",
|
||||||
},
|
},
|
||||||
StandardClaims: jwt.StandardClaims{
|
RegisteredClaims: jwt.RegisteredClaims{
|
||||||
ExpiresAt: time.Now().Add(time.Minute * srv.config.JwtExpiresIn).Unix(),
|
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * srv.config.JwtExpiresIn)),
|
||||||
IssuedAt: time.Now().Unix(),
|
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,7 @@ import (
|
|||||||
"github.com/ONLYOFFICE/document-server-integration/server/models"
|
"github.com/ONLYOFFICE/document-server-integration/server/models"
|
||||||
"github.com/ONLYOFFICE/document-server-integration/server/shared"
|
"github.com/ONLYOFFICE/document-server-integration/server/shared"
|
||||||
"github.com/ONLYOFFICE/document-server-integration/utils"
|
"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) {
|
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),
|
Link: remoteAddr + "/editor?filename=" + url.QueryEscape(fileName),
|
||||||
Path: fileName,
|
Path: fileName,
|
||||||
StandardClaims: jwt.StandardClaims{
|
RegisteredClaims: jwt.RegisteredClaims{
|
||||||
ExpiresAt: time.Now().Add(time.Minute * srv.config.JwtExpiresIn).Unix(),
|
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * srv.config.JwtExpiresIn)),
|
||||||
IssuedAt: time.Now().Unix(),
|
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/ONLYOFFICE/document-server-integration/server/models"
|
"github.com/ONLYOFFICE/document-server-integration/server/models"
|
||||||
"github.com/golang-jwt/jwt"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DocumentManager interface {
|
type DocumentManager interface {
|
||||||
|
|||||||
@ -27,7 +27,7 @@ import (
|
|||||||
|
|
||||||
"github.com/ONLYOFFICE/document-server-integration/config"
|
"github.com/ONLYOFFICE/document-server-integration/config"
|
||||||
"github.com/ONLYOFFICE/document-server-integration/server/managers"
|
"github.com/ONLYOFFICE/document-server-integration/server/managers"
|
||||||
"github.com/golang-jwt/jwt"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DefaultCommandManager struct {
|
type DefaultCommandManager struct {
|
||||||
@ -40,13 +40,13 @@ type CommandPayload struct {
|
|||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
Meta interface{} `json:"meta"`
|
Meta interface{} `json:"meta"`
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
jwt.StandardClaims
|
jwt.RegisteredClaims
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommandRequestHeaderPayload struct {
|
type CommandRequestHeaderPayload struct {
|
||||||
Query map[string]string `json:"query"`
|
Query map[string]string `json:"query"`
|
||||||
Payload CommandPayload `json:"payload"`
|
Payload CommandPayload `json:"payload"`
|
||||||
jwt.StandardClaims
|
jwt.RegisteredClaims
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDefaultCommandManager(config config.ApplicationConfig, jmanager managers.JwtManager) managers.CommandManager {
|
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{
|
payload := CommandPayload{
|
||||||
C: method,
|
C: method,
|
||||||
Key: docKey,
|
Key: docKey,
|
||||||
StandardClaims: jwt.StandardClaims{
|
RegisteredClaims: jwt.RegisteredClaims{
|
||||||
ExpiresAt: time.Now().Add(time.Minute * cm.config.JwtExpiresIn).Unix(),
|
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * cm.config.JwtExpiresIn)),
|
||||||
IssuedAt: time.Now().Unix(),
|
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if meta != nil {
|
if meta != nil {
|
||||||
@ -119,9 +119,9 @@ func fillJwtByUrl(uri string, payload CommandPayload, config config.ApplicationC
|
|||||||
return CommandRequestHeaderPayload{
|
return CommandRequestHeaderPayload{
|
||||||
Query: queryMap,
|
Query: queryMap,
|
||||||
Payload: payload,
|
Payload: payload,
|
||||||
StandardClaims: jwt.StandardClaims{
|
RegisteredClaims: jwt.RegisteredClaims{
|
||||||
ExpiresAt: time.Now().Add(time.Minute * config.JwtExpiresIn).Unix(),
|
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * config.JwtExpiresIn)),
|
||||||
IssuedAt: time.Now().Unix(),
|
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,7 @@ import (
|
|||||||
"github.com/ONLYOFFICE/document-server-integration/server/managers"
|
"github.com/ONLYOFFICE/document-server-integration/server/managers"
|
||||||
"github.com/ONLYOFFICE/document-server-integration/server/shared"
|
"github.com/ONLYOFFICE/document-server-integration/server/shared"
|
||||||
"github.com/ONLYOFFICE/document-server-integration/utils"
|
"github.com/ONLYOFFICE/document-server-integration/utils"
|
||||||
"github.com/golang-jwt/jwt"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -115,9 +115,9 @@ func (cm DefaultConversionManager) GetConverterUri(
|
|||||||
Title: title,
|
Title: title,
|
||||||
Key: docKey,
|
Key: docKey,
|
||||||
Async: isAsync,
|
Async: isAsync,
|
||||||
StandardClaims: jwt.StandardClaims{
|
RegisteredClaims: jwt.RegisteredClaims{
|
||||||
ExpiresAt: time.Now().Add(time.Minute * cm.config.JwtExpiresIn).Unix(),
|
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * cm.config.JwtExpiresIn)),
|
||||||
IssuedAt: time.Now().Unix(),
|
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,9 +128,9 @@ func (cm DefaultConversionManager) GetConverterUri(
|
|||||||
if secret != "" && cm.config.JwtEnabled {
|
if secret != "" && cm.config.JwtEnabled {
|
||||||
headerPayload := managers.ConvertRequestHeaderPayload{
|
headerPayload := managers.ConvertRequestHeaderPayload{
|
||||||
Payload: payload,
|
Payload: payload,
|
||||||
StandardClaims: jwt.StandardClaims{
|
RegisteredClaims: jwt.RegisteredClaims{
|
||||||
ExpiresAt: time.Now().Add(time.Minute * cm.config.JwtExpiresIn).Unix(),
|
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * cm.config.JwtExpiresIn)),
|
||||||
IssuedAt: time.Now().Unix(),
|
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
headerToken, err = cm.JwtManager.JwtSign(headerPayload, []byte(secret))
|
headerToken, err = cm.JwtManager.JwtSign(headerPayload, []byte(secret))
|
||||||
|
|||||||
@ -28,7 +28,7 @@ import (
|
|||||||
"github.com/ONLYOFFICE/document-server-integration/server/managers"
|
"github.com/ONLYOFFICE/document-server-integration/server/managers"
|
||||||
"github.com/ONLYOFFICE/document-server-integration/server/models"
|
"github.com/ONLYOFFICE/document-server-integration/server/models"
|
||||||
"github.com/ONLYOFFICE/document-server-integration/utils"
|
"github.com/ONLYOFFICE/document-server-integration/utils"
|
||||||
"github.com/golang-jwt/jwt"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -227,9 +227,9 @@ func (dm DefaultDocumentManager) BuildDocumentConfig(
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
StandardClaims: jwt.StandardClaims{
|
RegisteredClaims: jwt.RegisteredClaims{
|
||||||
ExpiresAt: time.Now().Add(time.Minute * dm.config.JwtExpiresIn).Unix(),
|
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * dm.config.JwtExpiresIn)),
|
||||||
IssuedAt: time.Now().Unix(),
|
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,7 +30,7 @@ import (
|
|||||||
"github.com/ONLYOFFICE/document-server-integration/server/models"
|
"github.com/ONLYOFFICE/document-server-integration/server/models"
|
||||||
"github.com/ONLYOFFICE/document-server-integration/server/shared"
|
"github.com/ONLYOFFICE/document-server-integration/server/shared"
|
||||||
"github.com/ONLYOFFICE/document-server-integration/utils"
|
"github.com/ONLYOFFICE/document-server-integration/utils"
|
||||||
"github.com/golang-jwt/jwt"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -197,9 +197,9 @@ func (hm DefaultHistoryManager) fetchNextHistoryEntry(
|
|||||||
Key: key,
|
Key: key,
|
||||||
Url: url,
|
Url: url,
|
||||||
Version: version,
|
Version: version,
|
||||||
StandardClaims: jwt.StandardClaims{
|
RegisteredClaims: jwt.RegisteredClaims{
|
||||||
ExpiresAt: time.Now().Add(time.Minute * hm.config.JwtExpiresIn).Unix(),
|
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * hm.config.JwtExpiresIn)),
|
||||||
IssuedAt: time.Now().Unix(),
|
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -267,9 +267,9 @@ func (hm DefaultHistoryManager) GetHistory(
|
|||||||
Url: hm.StorageManager.GeneratePublicFileUri(filename, remoteAddress, managers.FileMeta{}),
|
Url: hm.StorageManager.GeneratePublicFileUri(filename, remoteAddress, managers.FileMeta{}),
|
||||||
Version: version,
|
Version: version,
|
||||||
ChangesUrl: changesUrl,
|
ChangesUrl: changesUrl,
|
||||||
StandardClaims: jwt.StandardClaims{
|
RegisteredClaims: jwt.RegisteredClaims{
|
||||||
ExpiresAt: time.Now().Add(time.Minute * hm.config.JwtExpiresIn).Unix(),
|
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * hm.config.JwtExpiresIn)),
|
||||||
IssuedAt: time.Now().Unix(),
|
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -24,7 +24,7 @@ import (
|
|||||||
"github.com/ONLYOFFICE/document-server-integration/config"
|
"github.com/ONLYOFFICE/document-server-integration/config"
|
||||||
"github.com/ONLYOFFICE/document-server-integration/server/managers"
|
"github.com/ONLYOFFICE/document-server-integration/server/managers"
|
||||||
"github.com/ONLYOFFICE/document-server-integration/server/models"
|
"github.com/ONLYOFFICE/document-server-integration/server/models"
|
||||||
"github.com/golang-jwt/jwt"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|||||||
@ -21,7 +21,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/ONLYOFFICE/document-server-integration/server/models"
|
"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")
|
var ErrInvalidFilename = errors.New("invalid filename")
|
||||||
@ -39,7 +39,7 @@ type HistorySet struct {
|
|||||||
Url string `json:"url"`
|
Url string `json:"url"`
|
||||||
Version int `json:"version"`
|
Version int `json:"version"`
|
||||||
Token string `json:"token,omitempty"`
|
Token string `json:"token,omitempty"`
|
||||||
jwt.StandardClaims
|
jwt.RegisteredClaims
|
||||||
}
|
}
|
||||||
|
|
||||||
type HistoryPrevious struct {
|
type HistoryPrevious struct {
|
||||||
@ -99,10 +99,10 @@ type ConvertRequestPayload struct {
|
|||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
Async bool `json:"async"`
|
Async bool `json:"async"`
|
||||||
JwtToken string `json:"token,omitempty"`
|
JwtToken string `json:"token,omitempty"`
|
||||||
jwt.StandardClaims
|
jwt.RegisteredClaims
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConvertRequestHeaderPayload struct {
|
type ConvertRequestHeaderPayload struct {
|
||||||
Payload ConvertRequestPayload `json:"payload"`
|
Payload ConvertRequestPayload `json:"payload"`
|
||||||
jwt.StandardClaims
|
jwt.RegisteredClaims
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import "github.com/golang-jwt/jwt"
|
import "github.com/golang-jwt/jwt/v5"
|
||||||
|
|
||||||
type Command int
|
type Command int
|
||||||
|
|
||||||
@ -38,9 +38,9 @@ func (c Command) Ordinal() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CommandBody struct {
|
type CommandBody struct {
|
||||||
Command string `json:"c"`
|
Command string `json:"c"`
|
||||||
Token string `json:"token,omitempty"`
|
Token string `json:"token,omitempty"`
|
||||||
jwt.StandardClaims `json:"-"`
|
jwt.RegisteredClaims `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommandResponse struct {
|
type CommandResponse struct {
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import "github.com/golang-jwt/jwt"
|
import "github.com/golang-jwt/jwt/v5"
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
@ -25,5 +25,5 @@ type Config struct {
|
|||||||
DocumentType string `json:"documentType"`
|
DocumentType string `json:"documentType"`
|
||||||
EditorConfig EditorConfig `json:"editorConfig"`
|
EditorConfig EditorConfig `json:"editorConfig"`
|
||||||
Token string `json:"token,omitempty"`
|
Token string `json:"token,omitempty"`
|
||||||
jwt.StandardClaims
|
jwt.RegisteredClaims
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import "github.com/golang-jwt/jwt"
|
import "github.com/golang-jwt/jwt/v5"
|
||||||
|
|
||||||
type ReferenceData struct {
|
type ReferenceData struct {
|
||||||
FileKey string `json:"fileKey"`
|
FileKey string `json:"fileKey"`
|
||||||
@ -32,5 +32,5 @@ type Reference struct {
|
|||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
Url string `json:"url"`
|
Url string `json:"url"`
|
||||||
Token string `json:"token,omitempty"`
|
Token string `json:"token,omitempty"`
|
||||||
jwt.StandardClaims
|
jwt.RegisteredClaims
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user