go-github icon indicating copy to clipboard operation
go-github copied to clipboard

Unable to Parse Private Key

Open coleglencairn opened this issue 6 months ago • 8 comments

Hi, I am trying to use the ghinstallation ghinstallation.New() method, as referenced in the docs, to create a transport for use in my github client, but I am having trouble with my RSA key being parsed. When I used ghinstallation.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 their transport_test.go they are doing it the exact same way and I have to assume the tests are passing. I tried using go-githubauth as well, but ran into the same issue so it seems like the problem may exist somewhere in here for reading the key value in this way. Am I missing something?

  • key declaration: https://github.com/bradleyfalzon/ghinstallation/blob/d680810648e94347929da00376d1e7067f3572dd/transport_test.go#L27-L53
  • using key in New(): https://github.com/bradleyfalzon/ghinstallation/blob/d680810648e94347929da00376d1e7067f3572dd/transport_test.go#L167

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})

coleglencairn avatar Aug 07 '24 20:08 coleglencairn