bradleyfalzon / ghinstallation

HTTP Round Tripper for GitHub Apps - Authenticate as an Installation Workflow
Apache License 2.0
317 stars 98 forks source link

403 from client init #112

Open adrien-barret opened 10 months ago

adrien-barret commented 10 months ago

Hi,

I'm trying to use ghinstallation but I m facing a issue with token auth.

2024/01/18 21:17:55 Get "https://api.github.com/orgs/my-organization/teams": could not refresh installation id 47247922's token: received non 2xx response status "403 Forbidden" when fetching https://github.com/app/installations/47247922/access_tokens

code:

func main() {
    tr := http.DefaultTransport
    var AppID int64 = 120309
    var InstallationID int64 = 47247922
    // Wrap the shared transport for use with the app ID 1 authenticating with installation ID 99.
    itr, err := ghinstallation.NewKeyFromFile(tr, AppID, InstallationID, "my-private-key.private-key.pem")
    if err != nil {
        log.Fatal(err)
    }
    itr.BaseURL = GitHubEnterpriseURL

    ctx := context.Background()
    opt := &github.ListOptions{}

    client := github.NewClient(&http.Client{Transport: itr})

    ListTeams, _, err := client.Teams.ListTeams(ctx, "my-organization", opt)
    if err != nil {
        log.Fatal(err)
    }
    log.Println(ListTeams)
}

not sure to understand correctly but the call stop at the authentication. the github account is a paid organization in github saas not self hosted. The permissions look like: Read access to actions, members, metadata, organization administration, and pull requests

What I don't understand is that path https://github.com/app/installations/47247922/access_tokens it seems to miss something. If I look my application the url is https://github.com/organizations/my-organization/settings/installations/47247922

I would presume the url needed would be https://github.com/organizations/my-organization/settings/installations/47247922/access_tokens or does I miss something? @bradleyfalzon

jcucuzza commented 1 week ago

I had a similar issue and was able to resolve it by creating a new private key on my github app and updating my code to use it.