fix(deps): update module github.com/golang-jwt/jwt/v4 to v5
This commit is contained in:
+1
-1
@@ -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
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user