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

ghclient.AppsService requires JWT authentication #39

Open
botchniaque opened this issue Jul 9, 2020 · 1 comment
Open

ghclient.AppsService requires JWT authentication #39

botchniaque opened this issue Jul 9, 2020 · 1 comment

Comments

@botchniaque
Copy link

botchniaque commented Jul 9, 2020

Almost all operations in githubClient require installation access token, except calls made by AppsService which require JWT.

Following the instructions in the readme makes it impossible to get the AppsService calls work. I work around the issue by creating a separate client for apps calls using the AppsTransport, and using the other installation Transport to make all other calls.

It would be great if one could create single client using the correct auth method depending on the call.

My workaround:

const gheBaseUrl = "https://my-ghe-installation-url/api/v3"

tr := http.DefaultTransport
appId := 99
installationId := 99

jwtTransport, _ := ghinstallation.NewAppsTransportKeyFromFile(tr, appId, "path/to/key.pem")
installationTokenTransport := ghinstallation.NewFromAppsTransport(jwtTransport, installationId)

installationTokenTransport.BaseURL = gheBaseUrl
jwtTransport.BaseURL = gheBaseUrl

ghClient, _ := github.NewEnterpriseClient(gheBaseUrl, fmt.Sprintf("%s/upload", gheBaseUrl), &http.Client{Transport: installationTokenTransport})
appsGhClient, _ := github.NewEnterpriseClient(gheBaseUrl, fmt.Sprintf("%s/upload", gheBaseUrl),&http.Client{Transport: jwtTransport})

// this client can authenticate all calls except `Apps.Get()`
ghClient.Apps = appsGhClient.Apps


@wlynch
Copy link
Collaborator

wlynch commented Mar 8, 2021

I'm not sure this is something that should be handled in ghinstallation - this library itself isn't actually aware of the API calls being made beyond the get installation token method.
What's nice about this is that ghinstallation doesn't need to be updated for any new API calls.

I'm also not sure if there are endpoints that can be authenticated with both a JWT or installation token, which could make knowing the auth method to use ambiguous in certain cases based on URL path alone.

It probably makes more sense to make this type of decision in the client (e.g. go-github) where we know for certain what token we need to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants