Skip to content

Commit d083ac5

Browse files
authored
[CLOUDTRUST-5687] Change jwt library (#22)
1 parent 7e224d2 commit d083ac5

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

authorization.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"net/url"
77
"time"
88

9-
jwt "github.com/gbrlsnchs/jwt/v2"
9+
"github.com/golang-jwt/jwt/v5"
1010
"github.com/pkg/errors"
1111
"gopkg.in/h2non/gentleman.v2"
1212
"gopkg.in/h2non/gentleman.v2/context"
@@ -95,16 +95,16 @@ func extractHostFromToken(token string) (string, error) {
9595
return u.Host, nil
9696
}
9797

98-
func extractIssuerFromToken(token string) (string, error) {
99-
payload, _, err := jwt.Parse(token)
98+
func extractIssuerFromToken(tokenStr string) (string, error) {
99+
token, _, err := jwt.NewParser().ParseUnverified(tokenStr, jwt.MapClaims{})
100100
if err != nil {
101101
return "", errors.Wrap(err, MsgErrCannotParse+"."+PrmTokenMsg)
102102
}
103103

104-
var jot Token
105-
if err = jwt.Unmarshal(payload, &jot); err != nil {
106-
return "", errors.Wrap(err, MsgErrCannotUnmarshal+"."+PrmTokenMsg)
104+
issuer, err := token.Claims.GetIssuer()
105+
if err != nil {
106+
return "", errors.Wrap(err, MsgErrCannotGetIssuer+"."+PrmTokenMsg)
107107
}
108108

109-
return jot.Issuer, nil
109+
return issuer, nil
110110
}

errors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
// Constants for error management
99
const (
1010
MsgErrCannotObtain = "cannotObtain"
11-
MsgErrCannotUnmarshal = "cannotUnmarshal"
11+
MsgErrCannotGetIssuer = "cannotGetIssuer"
1212
MsgErrCannotParse = "cannotParse"
1313
MsgErrUnkownHTTPContentType = "unkownHTTPContentType"
1414
MsgErrUnknownResponseStatusCode = "unknownResponseStatusCode"

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/cloudtrust/httpclient
33
go 1.22
44

55
require (
6-
github.com/gbrlsnchs/jwt/v2 v2.0.0
6+
github.com/golang-jwt/jwt/v5 v5.2.1
77
github.com/golang/mock v1.6.0
88
github.com/gorilla/mux v1.8.1
99
github.com/pkg/errors v0.9.1

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/gbrlsnchs/jwt/v2 v2.0.0 h1:4iEVJykJPXrCimVaQJAfBWKAvuzDJi5fDdUBdrdTZ3M=
4-
github.com/gbrlsnchs/jwt/v2 v2.0.0/go.mod h1:7kIj4oeJPffUpLL8RnU5Y3xT1Sm/VuFqjv8T1tqhqc8=
3+
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
4+
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
55
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
66
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
77
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=

vendor/modules.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
github.com/davecgh/go-spew/spew
44
# github.com/gbrlsnchs/jwt/v2 v2.0.0
55
## explicit
6-
github.com/gbrlsnchs/jwt/v2
6+
# github.com/golang-jwt/jwt/v5 v5.2.1
7+
## explicit; go 1.18
8+
github.com/golang-jwt/jwt/v5
79
# github.com/golang/mock v1.6.0
810
## explicit; go 1.11
911
github.com/golang/mock/mockgen/model

0 commit comments

Comments
 (0)