Skip to content

Commit

Permalink
Don't use a pointer to an interface (#117)
Browse files Browse the repository at this point in the history
This is part of a cleanup for #116. In golang-jwt, Token is a struct. In jwx, it's an interface. Returning a pointer to an interface is generally frowned upon. This changes the interface to always be returned as an interface, but there needs to be a larger effort around reducing to a single jwt library.
  • Loading branch information
sethvargo authored Sep 15, 2022
1 parent 5ab0828 commit db26d44
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions client-lib/go/client/jvs_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func NewJVSClient(ctx context.Context, config *JVSConfig) (*JVSClient, error) {
}

// ValidateJWT takes a jwt string, converts it to a JWT, and validates the signature.
func (j *JVSClient) ValidateJWT(jwtStr string) (*jwt.Token, error) {
func (j *JVSClient) ValidateJWT(jwtStr string) (jwt.Token, error) {
// Handle unsigned tokens.
if strings.HasSuffix(jwtStr, UnsignedPostfix) {
token, err := jwt.Parse([]byte(jwtStr), jwt.WithVerify(false))
Expand All @@ -74,7 +74,7 @@ func (j *JVSClient) ValidateJWT(jwtStr string) (*jwt.Token, error) {
if err := j.unsignedTokenValidAndAllowed(token); err != nil {
return nil, fmt.Errorf("token unsigned and could not be validated: %w", err)
}
return &token, nil
return token, nil
}
return jvscrypto.ValidateJWT(j.keys, jwtStr)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/jvscrypto/kmsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,13 @@ func getLabelValue(versionName string) (string, error) {
}

// ValidateJWT takes a jwt string, converts it to a JWT, and validates the signature.
func ValidateJWT(keySet jwk.Set, jwtStr string) (*jwt2.Token, error) {
func ValidateJWT(keySet jwk.Set, jwtStr string) (jwt2.Token, error) {
verifiedToken, err := jwt2.Parse([]byte(jwtStr), jwt2.WithKeySet(keySet, jws.WithInferAlgorithmFromKey(true)))
if err != nil {
return nil, fmt.Errorf("failed to verify jwt %s: %w", jwtStr, err)
}

return &verifiedToken, nil
return verifiedToken, nil
}

// JWKList creates a list of public keys in JWK format.
Expand Down
2 changes: 1 addition & 1 deletion test/integ/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func TestJVS(t *testing.T) {
return
}

tokenMap, err := (*token).AsMap(ctx)
tokenMap, err := token.AsMap(ctx)
if err != nil {
t.Errorf("Couldn't convert token to map: %v", err)
return
Expand Down

0 comments on commit db26d44

Please sign in to comment.