Skip to content

RFC: add a SignerWithContext interface for custom sign implementations #117

Description

@jamestelfer

The current sign interface has the single Sign method:

Sign(claims jwt.Claims) (string, error)

When implementing an AWS KMS signer, the lack of the context means the remote operation doesn't participate in the main context, so it's unaware of request timeouts or server shutdown.

What about adding:

type SignerWithContext interface {
    Sign(ctx context.Context, claims jwt.Claims) (string, error)
}

An existing Signer implementation can be supported through a simple wrapper function:

type SignerWithContextFunc func Sign(claims jwt.Claims) (string, error)

func (s SignerWithContextFunc) (_ context.Context, claims jwt.Claims) (string, error) {
    return s(claims)
}

// ... 

signer := // Signer implementation
contextSigner := SignerWithContextFunc(signer.Sign)

Then a configuration item for WithContextSigner or similar. Thoughts?

I am able to raise a PR for this, or some more acceptable variation.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions