Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgraded to golang-jwt v5 #446

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"time"

"github.com/go-resty/resty/v2"
"github.com/golang-jwt/jwt/v4"
"github.com/golang-jwt/jwt/v5"
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/segmentio/ksuid"
Expand Down Expand Up @@ -881,7 +881,7 @@
Put(g.getAdminRealmURL(realm, "groups", idOfGroup, "management", "permissions"))

if err := checkForError(resp, err, errMessage); err != nil {
return nil, err

Check warning on line 884 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L884

Added line #L884 was not covered by tests
}

return &result, nil
Expand Down Expand Up @@ -936,7 +936,7 @@
Put(g.getAdminRealmURL(realm, "clients", idOfClient, "management", "permissions"))

if err := checkForError(resp, err, errMessage); err != nil {
return nil, err

Check warning on line 939 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L939

Added line #L939 was not covered by tests
}

return &result, nil
Expand Down Expand Up @@ -1461,7 +1461,7 @@

queryParams, err = GetQueryParams(params[0])
if err != nil {
return nil, errors.Wrap(err, errMessage)

Check warning on line 1464 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L1464

Added line #L1464 was not covered by tests
}
}

Expand All @@ -1488,7 +1488,7 @@

queryParams, err = GetQueryParams(params[0])
if err != nil {
return nil, errors.Wrap(err, errMessage)

Check warning on line 1491 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L1491

Added line #L1491 was not covered by tests
}
}

Expand Down Expand Up @@ -1751,7 +1751,7 @@
Get(g.getAdminRealmURL(realm, "groups", idOfGroup, "management", "permissions"))

if err := checkForError(resp, err, errMessage); err != nil {
return nil, err

Check warning on line 1754 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L1754

Added line #L1754 was not covered by tests
}

return &result, nil
Expand Down Expand Up @@ -2030,7 +2030,7 @@
Get(g.getAdminRealmURL(realm, "clients", idOfClient, "management", "permissions"))

if err := checkForError(resp, err, errMessage); err != nil {
return nil, err

Check warning on line 2033 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L2033

Added line #L2033 was not covered by tests
}

return &result, nil
Expand Down Expand Up @@ -3419,7 +3419,7 @@
Get(g.getAdminRealmURL(realm, "clients", idOfClient, "authz", "resource-server", "permission", "scope", idOfScope))

if err := checkForError(resp, err, errMessage); err != nil {
return nil, err

Check warning on line 3422 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L3422

Added line #L3422 was not covered by tests
}

return &result, nil
Expand Down
4 changes: 2 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"time"

"github.com/go-resty/resty/v2"
"github.com/golang-jwt/jwt/v4"
"github.com/golang-jwt/jwt/v5"
"github.com/stretchr/testify/require"
"golang.org/x/crypto/pkcs12"

Expand Down Expand Up @@ -6258,7 +6258,7 @@ func Test_CreatePermissionTicket(t *testing.T) {
})

// we're expecting validity error because we didn't supply secret
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message changed due to the upgrade, so I just changed the test to check if the returned error is the ErrTokenSignatureInvalid error, instead of comparing the text

require.Equal(t, "signature is invalid", err.Error())
require.ErrorIs(t, err, jwt.ErrTokenSignatureInvalid)

claims, ok := pt.Claims.(*gocloak.PermissionTicketRepresentation) // ticketClaims)
require.Equal(t, true, ok)
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ go 1.18

require (
github.com/go-resty/resty/v2 v2.7.0
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/golang-jwt/jwt/v5 v5.0.0
github.com/opentracing/opentracing-go v1.2.0
github.com/pkg/errors v0.9.1
github.com/segmentio/ksuid v1.0.4
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crypto needed to be updated in order to bump golang.org/x/net

github.com/stretchr/testify v1.8.2
golang.org/x/crypto v0.6.0
golang.org/x/crypto v0.14.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/net v0.17.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ 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/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY=
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE=
github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand All @@ -21,11 +21,11 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down
4 changes: 2 additions & 2 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"strings"

"github.com/golang-jwt/jwt/v4"
"github.com/golang-jwt/jwt/v5"
)

// GetQueryParams converts the struct to map[string]string
Expand Down Expand Up @@ -1258,7 +1258,7 @@ type PermissionTicketRepresentation struct {
AZP *string `json:"azp,omitempty"`
Claims *map[string][]string `json:"claims,omitempty"`
Permissions *[]PermissionTicketPermissionRepresentation `json:"permissions,omitempty"`
jwt.StandardClaims
jwt.RegisteredClaims
}

// PermissionTicketPermissionRepresentation represents the individual permissions in a permission ticket
Expand Down
2 changes: 1 addition & 1 deletion pkg/jwx/jwx.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"math/big"
"strings"

"github.com/golang-jwt/jwt/v4"
"github.com/golang-jwt/jwt/v5"
"github.com/pkg/errors"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/jwx/jwx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/golang-jwt/jwt/v4"
"github.com/golang-jwt/jwt/v5"
)

var claims = jwt.MapClaims{
Expand Down
4 changes: 2 additions & 2 deletions pkg/jwx/models.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package jwx

import jwt "github.com/golang-jwt/jwt/v4"
import jwt "github.com/golang-jwt/jwt/v5"

// DecodedAccessTokenHeader is the decoded header from the access token
type DecodedAccessTokenHeader struct {
Expand All @@ -11,7 +11,7 @@ type DecodedAccessTokenHeader struct {

// Claims served by keycloak inside the accessToken
type Claims struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StandardClaims has been deprecated for a while, and was finally removed in v5. RegisteredClaims is the new equivalent.

jwt.StandardClaims
jwt.RegisteredClaims
Typ string `json:"typ,omitempty"`
Azp string `json:"azp,omitempty"`
AuthTime int `json:"auth_time,omitempty"`
Expand Down
Loading