stytchauth / stytch-go

Official Stytch Backend SDK for Go
MIT License
47 stars 10 forks source link

Add client setup options for init Context and HTTP client #122

Closed jeremy-stytch closed 1 year ago

jeremy-stytch commented 1 year ago

This PR contains two changes related to API client startup. In order of importance:

  1. Accept an init context to use when starting the API client. This allows canceling client creation if the initial JWKS fetch takes too long.

    The easiest way to get this done was to upgrade through keyfunc v2.0.1 (which has a context bugfix). This is something nice to do anyway.

    This option is different from our other stytchapi.Option arguments because it doesn't change the underlying API client in any way. So the init context can't easily be set as one of the variadic option args. Instead, there's a new client constructor that takes the context as the first argument.

  2. Add an HTTP client override option. This is useful for anyone who needs to override the HTTP client to change things like the transport settings.

    This one can be done as one of the variadic option args, so we don't have to do anything special for it.

Migration Guide

If you need to control the setup context for the Stytch API client, use NewAPIClientWithContext instead of NewAPIClient. You can keep same behavior by passing context.Background() as the context, which will allow unlimited time for client creation.

Reviewer Notes

I intend to rebase-merge the commits in this PR, which is unusual for this repo. Please review the individual commits.

This is the same as #121 except that the init context changes are done in a non-breaking way. So this does not contain any of the add-on major-version changes.