fix(deps): update module github.com/golang-jwt/jwt/v4 to v5

This commit is contained in:
Renovate
2024-03-01 19:53:09 +00:00
committed by Joakim Olsson
parent 04750fca3c
commit 86bc1801b8
4 changed files with 7 additions and 20 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"net/http"
"github.com/99designs/gqlgen/graphql"
"github.com/golang-jwt/jwt/v4"
"github.com/golang-jwt/jwt/v5"
"gitlab.com/unboundsoftware/schemas/domain"
"gitlab.com/unboundsoftware/schemas/hash"
+3 -18
View File
@@ -11,7 +11,7 @@ import (
"time"
mw "github.com/auth0/go-jwt-middleware/v2"
"github.com/golang-jwt/jwt/v4"
"github.com/golang-jwt/jwt/v5"
"github.com/pkg/errors"
)
@@ -56,20 +56,8 @@ type JSONWebKeys struct {
}
func (a *Auth0) ValidationKeyGetter() func(token *jwt.Token) (interface{}, error) {
issuer := fmt.Sprintf("https://%s/", a.domain)
return func(token *jwt.Token) (interface{}, error) {
// Verify 'aud' claim
aud := a.audience
checkAud := token.Claims.(jwt.MapClaims).VerifyAudience(aud, false)
if !checkAud {
return token, errors.New("Invalid audience.")
}
// Verify 'iss' claim
iss := issuer
checkIss := token.Claims.(jwt.MapClaims).VerifyIssuer(iss, false)
if !checkIss {
return token, errors.New("Invalid issuer.")
}
cert, err := a.getPemCert(token)
if err != nil {
@@ -82,18 +70,15 @@ func (a *Auth0) ValidationKeyGetter() func(token *jwt.Token) (interface{}, error
}
func (a *Auth0) Middleware() *mw.JWTMiddleware {
issuer := fmt.Sprintf("https://%s/", a.domain)
jwtMiddleware := mw.New(func(ctx context.Context, token string) (interface{}, error) {
jwtToken, err := jwt.Parse(token, a.ValidationKeyGetter())
jwtToken, err := jwt.Parse(token, a.ValidationKeyGetter(), jwt.WithAudience(a.audience), jwt.WithIssuer(issuer))
if err != nil {
return nil, err
}
if _, ok := jwtToken.Method.(*jwt.SigningMethodRSA); !ok {
return nil, fmt.Errorf("unexpected signing method: %v", jwtToken.Header["alg"])
}
err = jwtToken.Claims.Valid()
if err != nil {
return nil, err
}
return jwtToken, nil
},
mw.WithTokenExtractor(func(r *http.Request) (string, error) {