From e0fa0e645bcfffa49682fbbaced01051e780e235 Mon Sep 17 00:00:00 2001 From: Kilian Schneiter Date: Tue, 17 Dec 2024 17:49:11 +0100 Subject: [PATCH] [CLOUDTRUST-5687] Change jwt library --- authorization.go | 14 +++++++------- errors.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- vendor/modules.txt | 4 +++- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/authorization.go b/authorization.go index 94f2d3c..8447468 100644 --- a/authorization.go +++ b/authorization.go @@ -6,7 +6,7 @@ import ( "net/url" "time" - jwt "github.com/gbrlsnchs/jwt/v2" + "github.com/golang-jwt/jwt/v5" "github.com/pkg/errors" "gopkg.in/h2non/gentleman.v2" "gopkg.in/h2non/gentleman.v2/context" @@ -95,16 +95,16 @@ func extractHostFromToken(token string) (string, error) { return u.Host, nil } -func extractIssuerFromToken(token string) (string, error) { - payload, _, err := jwt.Parse(token) +func extractIssuerFromToken(tokenStr string) (string, error) { + token, _, err := jwt.NewParser().ParseUnverified(tokenStr, jwt.MapClaims{}) if err != nil { return "", errors.Wrap(err, MsgErrCannotParse+"."+PrmTokenMsg) } - var jot Token - if err = jwt.Unmarshal(payload, &jot); err != nil { - return "", errors.Wrap(err, MsgErrCannotUnmarshal+"."+PrmTokenMsg) + issuer, err := token.Claims.GetIssuer() + if err != nil { + return "", errors.Wrap(err, MsgErrCannotGetIssuer+"."+PrmTokenMsg) } - return jot.Issuer, nil + return issuer, nil } diff --git a/errors.go b/errors.go index b601c9d..fd16d00 100644 --- a/errors.go +++ b/errors.go @@ -8,7 +8,7 @@ import ( // Constants for error management const ( MsgErrCannotObtain = "cannotObtain" - MsgErrCannotUnmarshal = "cannotUnmarshal" + MsgErrCannotGetIssuer = "cannotGetIssuer" MsgErrCannotParse = "cannotParse" MsgErrUnkownHTTPContentType = "unkownHTTPContentType" MsgErrUnknownResponseStatusCode = "unknownResponseStatusCode" diff --git a/go.mod b/go.mod index 138b9d2..d559973 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/cloudtrust/httpclient go 1.22 require ( - github.com/gbrlsnchs/jwt/v2 v2.0.0 + github.com/golang-jwt/jwt/v5 v5.2.1 github.com/golang/mock v1.6.0 github.com/gorilla/mux v1.8.1 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 2447ddb..e6d0f63 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/gbrlsnchs/jwt/v2 v2.0.0 h1:4iEVJykJPXrCimVaQJAfBWKAvuzDJi5fDdUBdrdTZ3M= -github.com/gbrlsnchs/jwt/v2 v2.0.0/go.mod h1:7kIj4oeJPffUpLL8RnU5Y3xT1Sm/VuFqjv8T1tqhqc8= +github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= +github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= diff --git a/vendor/modules.txt b/vendor/modules.txt index 130c6a7..558b864 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -3,7 +3,9 @@ github.com/davecgh/go-spew/spew # github.com/gbrlsnchs/jwt/v2 v2.0.0 ## explicit -github.com/gbrlsnchs/jwt/v2 +# github.com/golang-jwt/jwt/v5 v5.2.1 +## explicit; go 1.18 +github.com/golang-jwt/jwt/v5 # github.com/golang/mock v1.6.0 ## explicit; go 1.11 github.com/golang/mock/mockgen/model