Repository navigation
Description
Hi,
Apart from the addition in #436, the new GitHub Integrations (https://developer.github.com/early-access/integrations/) requires a new authentication workflow, different from OAuth (https://developer.github.com/early-access/integrations/authentication/ as well as https://developer.github.com/early-access/integrations/integrations-vs-oauth-applications/).
As many APIs require this installation token (unique per installation of the integration, expires after short time period), I can easily (and do) provide a separate http.Client with a custom http.RoundTripper adding the necessary authentication headers, but, this requires a separate http.Client for every Integration installation, which means the underlying tcp connection is not being reused between installations (although I believe I can workaround that).
Further there is likely some room here to provide helpers for retrieving the required JWT tokens from a file as this is currently non-trivial and error prone (although just an example would be sufficient for most people).
I haven't developed a GitHub OAuth application before, so I'm not certain if the Integrations flow is any different, but ideally, I would like to be able to use a single client for all installations, swapping out the token on a per request basis - but I don't see how this could be possible without breaking api or not being thread safe (although I'm not certain on the safety guarantees already in place - I did look and couldn't see).
I haven't thought this through completely, and a separate client for each Integration installation maybe optimal (create another client, cache it for the life of the token), but I wanted to ask first if there has been some thought about how go-github would support with the new GitHub Integrations.
I have working prototype of a GitHub Integration and can provide samples if any maintainers want a quick start if no-one has started yet.
My current thinking (half tested):
- Single
http.Transport- ensures all derived clients reuse http connection. - Wrap that transport for each installation, the
installationTransportadds necessary authorisation headers and is responsible for renewing tokens if they expire. - Pass the
installationTransportinto ahttp.Clientinto agithub.Client.
Thanks
Activity
bradleyfalzon commentedon Oct 21, 2016
So to provide this via a http.RoundTripper, I've done:
Above is missing constructor as my implementation is slightly more complicated, can provide a simpler version if required.
To use this:
This generally works in dev, but hasn't been tested completely (in particular, I believe the TCP connections should be reused, but I haven't actually tested this), and I haven't ran this long enough to know tokens are refreshed, there's also an opportunity to split the refresh tokens into two steps to provide the ability to authenticate as an integration too (although the only use I have for it so far it to fetch tokens), I'm not a developer and little experience with GitHub APIs and this package so there maybe better options, and it's not clear on how rate limits are being implemented by GitHub right now (per integration rate limit or per installation). Feedback appreciated.
I'd like to know how this project would want to provide authentication for Integrations, as I know it doesn't currently provide OAuth, however, perhaps providing a similar transport would help people (there are a lot of steps specific to GitHub). If the project doesn't want to provide this (I can understand, I'll be glad to provide it as an external package).
Thanks
bradleyfalzon commentedon Oct 27, 2016
Hi,
I've provided this via a work-in-progress external package in the meantime: https://github.com/bradleyfalzon/ghinstallation
Feedback welcome, but for the moment, will close the issue.
Thanks
doc: Add link to GitHub Apps authentication package. (#649)
doc: Add link to GitHub Apps authentication package. (google#649)
doc: Add link to GitHub Apps authentication package. (google#649)