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

Accept a context in ValidateJWT #179

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
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
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