bradleyfalzon / ghinstallation

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

Unable to Parse Private Key Using New() #126

Open coleglencairn opened 3 months ago

coleglencairn commented 3 months ago

Hi, I am trying to use the New() method to create a transport for use in my github client, but I am having trouble with my RSA key being parsed. When I used NewKeyFromFile() everything worked fine, but swapping to New() and feeding in a string of the key as a byte gives me the following error: could not parse private key: Invalid Key: Key must be PEM encoded PKCS1 or PKCS8 private key. I am confused by this because in transport_test.go you are doing it the exact same way and I have to assume the tests are passing. I'm not sure if this is an issue in ghinstallation or go-github. Am I missing something?

My code is like this:

var key = `-----BEGIN RSA PRIVATE KEY-----
KEY GOES HERE
-----END RSA PRIVATE KEY-----`

itr, err := ghinstallation.New(
        http.DefaultTransport,
        99,
        123,
        []byte(key),
)
if err != nil {
log.Fatal("github authentication error: ", err)
}
githubClient := github.NewClient(&http.Client{Transport: itr})
tchajed commented 1 month ago

I can't reproduce this, filling in var key with the private key from transport_test.go.

Are you sure you're reading the private key from disk correctly (and not passing the file name for example)?

This would be an issue with ghinstallation rather than the github package because if authentication is failing, it's happening before you reach github.NewClient.