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

More descriptive JWT check error messages #838

Merged
merged 1 commit into from
Jun 26, 2024
Merged
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
18 changes: 9 additions & 9 deletions internal/jwtverify/token_verifier_jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,19 +410,19 @@ func (verifier *VerifierJWT) VerifyConnectToken(t string, skipVerify bool) (Conn
}

if verifier.audience != "" && !claims.IsForAudience(verifier.audience) {
return ConnectToken{}, ErrInvalidToken
return ConnectToken{}, fmt.Errorf("%w: invalid audience", ErrInvalidToken)
}

if verifier.issuer != "" && !claims.IsIssuer(verifier.issuer) {
return ConnectToken{}, ErrInvalidToken
return ConnectToken{}, fmt.Errorf("%w: invalid issuer", ErrInvalidToken)
}

tokenVars := map[string]any{}

if verifier.issuerRe != nil {
match := verifier.issuerRe.FindStringSubmatch(claims.Issuer)
if len(match) == 0 {
return ConnectToken{}, ErrInvalidToken
return ConnectToken{}, fmt.Errorf("%w: issuer not matched", ErrInvalidToken)
}
for i, name := range verifier.issuerRe.SubexpNames() {
if i != 0 && name != "" {
Expand All @@ -447,7 +447,7 @@ func (verifier *VerifierJWT) VerifyConnectToken(t string, skipVerify bool) (Conn
break
}
if !matched {
return ConnectToken{}, ErrInvalidToken
return ConnectToken{}, fmt.Errorf("%w: audience not matched", ErrInvalidToken)
}
}

Expand Down Expand Up @@ -604,19 +604,19 @@ func (verifier *VerifierJWT) VerifySubscribeToken(t string, skipVerify bool) (Su
}

if verifier.audience != "" && !claims.IsForAudience(verifier.audience) {
return SubscribeToken{}, ErrInvalidToken
return SubscribeToken{}, fmt.Errorf("%w: invalid audience", ErrInvalidToken)
}

if verifier.issuer != "" && !claims.IsIssuer(verifier.issuer) {
return SubscribeToken{}, ErrInvalidToken
return SubscribeToken{}, fmt.Errorf("%w: invalid issuer", ErrInvalidToken)
}

tokenVars := map[string]any{}

if verifier.issuerRe != nil {
match := verifier.issuerRe.FindStringSubmatch(claims.Issuer)
if len(match) == 0 {
return SubscribeToken{}, ErrInvalidToken
return SubscribeToken{}, fmt.Errorf("%w: issuer not matched", ErrInvalidToken)
}
for i, name := range verifier.issuerRe.SubexpNames() {
if i != 0 && name != "" {
Expand All @@ -641,7 +641,7 @@ func (verifier *VerifierJWT) VerifySubscribeToken(t string, skipVerify bool) (Su
break
}
if !matched {
return SubscribeToken{}, ErrInvalidToken
return SubscribeToken{}, fmt.Errorf("%w: audience not matched", ErrInvalidToken)
}
}

Expand All @@ -662,7 +662,7 @@ func (verifier *VerifierJWT) VerifySubscribeToken(t string, skipVerify bool) (Su
}

if claims.Channel == "" {
return SubscribeToken{}, ErrInvalidToken
return SubscribeToken{}, fmt.Errorf("%w: channel claim is required for subscription JWT", ErrInvalidToken)
}

_, _, chOpts, found, err := verifier.ruleContainer.ChannelOptions(claims.Channel)
Expand Down
Loading