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

Unable to Parse Private Key #3227

Open
coleglencairn opened this issue Aug 7, 2024 · 8 comments
Open

Unable to Parse Private Key #3227

coleglencairn opened this issue Aug 7, 2024 · 8 comments

Comments

@coleglencairn
Copy link

coleglencairn commented Aug 7, 2024

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?

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 coleglencairn changed the title Unable to Parse Private Key Using New() Unable to Parse Private Key Aug 7, 2024
@gmlewis
Copy link
Collaborator

gmlewis commented Aug 7, 2024

@bradleyfalzon - can you please comment?

@coleglencairn
Copy link
Author

Is there a native way to handle the auth without either of the other packages? I just need something to get me by for now and I would rather not have to read from a file for this value if I can help it.

@gmlewis
Copy link
Collaborator

gmlewis commented Aug 13, 2024

Did you take a look at this basic auth example?
https://github.com/google/go-github/blob/master/example/basicauth/main.go

@coleglencairn
Copy link
Author

Did you take a look at this basic auth example? https://github.com/google/go-github/blob/master/example/basicauth/main.go

Does that work for GitHub app auth?

@gmlewis
Copy link
Collaborator

gmlewis commented Aug 13, 2024

Sorry, I don't know. We'll need someone who has worked with GitHub app auth to respond.

@air-hand
Copy link
Contributor

@jferrl
Copy link
Contributor

jferrl commented Sep 7, 2024

Decode

I can take a look in https://github.com/jferrl/go-githubauth just to try to fix it.

@jferrl
Copy link
Contributor

jferrl commented Sep 7, 2024

Im trying to reproduce the issue with go-githubauth

package main

import (
	"fmt"

	"github.com/jferrl/go-githubauth"
)

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

func main() {
	_, err := githubauth.NewApplicationTokenSource(123456, []byte(key))
	if err != nil {
		fmt.Println("Error creating application token source:", err)
		return
	}
}

and seems to be ok. @coleglencairn

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

4 participants