Skip to content

Commit

Permalink
Accept a context in ValidateJWT (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethvargo authored and verbanicm committed Jan 26, 2023
1 parent cc6da44 commit 42f2338
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 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 @@ -58,7 +58,7 @@ func NewJVSClient(ctx context.Context, config *JVSConfig) (*JVSClient, error) {

// ValidateJWT takes a jwt string, converts it to a JWT, and validates the
// signature against the keys in the JWKs endpoint.
func (j *JVSClient) ValidateJWT(jwtStr string) (jwt.Token, error) {
func (j *JVSClient) ValidateJWT(ctx context.Context, jwtStr string) (jwt.Token, error) {
// Handle breakglass tokens
token, err := jvspb.ParseBreakglassToken(jwtStr)
if err != nil {
Expand All @@ -73,7 +73,7 @@ func (j *JVSClient) ValidateJWT(jwtStr string) (jwt.Token, error) {

// If we got this far, the token was not breakglass, so parse as normal.
token, err = jwt.ParseString(jwtStr,
jwt.WithContext(context.TODO()),
jwt.WithContext(ctx),
jvspb.WithTypedJustifications(),
jwt.WithKeySet(j.keys, jws.WithInferAlgorithmFromKey(true)),
)
Expand Down
2 changes: 1 addition & 1 deletion client-lib/go/client/jvs_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func TestValidateJWT(t *testing.T) {
if err != nil {
t.Fatalf("failed to create JVS client: %v", err)
}
res, err := client.ValidateJWT(tc.jwt)
res, err := client.ValidateJWT(ctx, tc.jwt)

if diff := testutil.DiffErrString(err, tc.wantErr); diff != "" {
t.Errorf("Unexpected err: %s", diff)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func runValidateCmd(cmd *cobra.Command, opts *validateCmdOptions, args []string)
if token != nil {
breakglass = true
} else {
token, err = jvsclient.ValidateJWT(opts.token)
token, err = jvsclient.ValidateJWT(ctx, opts.token)
if err != nil {
return fmt.Errorf("failed to validate jwt: %w", err)
}
Expand Down

0 comments on commit 42f2338

Please sign in to comment.