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

Integration must generate a public key #1080

Closed
jqtruong opened this issue Oct 10, 2018 · 11 comments
Closed

Integration must generate a public key #1080

jqtruong opened this issue Oct 10, 2018 · 11 comments

Comments

@jqtruong
Copy link

Hello, i'm getting an error:

POST https://api.github.com/installations/4/access_tokens: 401 - Integration must generate a public key // See: https://developer.github.com/v3:

i am following this guide, and the error stems from this function call:

installation_token = @client.create_app_installation_access_token(installation_id)[:token]

in the authenticate_installation.

Do you know why that might be happening?

@tarebyte
Copy link
Member

tarebyte commented Oct 10, 2018

@jqtruong can you show me how you're creating the @client ?

@jqtruong
Copy link
Author

@client ||= Octokit::Client.new(bearer_token: jwt)

i think i'm missing something, the :integrations, right? i am currently looking into how i can add that media type

@tarebyte
Copy link
Member

tarebyte commented Oct 10, 2018

The media type is built into the helper methods, how are you creating the jwt ?

@jqtruong
Copy link
Author

    payload = {
        # The time that this JWT was issued, _i.e._ now.
        iat: Time.now.to_i,

        # How long is the JWT good for (in seconds)?
        # Let's say it can be used for 10 minutes before it needs to be refreshed.
        # TODO we don't actually cache this token, we regenerate a new one every time!
        exp: Time.now.to_i + (10 * 60),

        # Your GitHub App's identifier number, so GitHub knows who issued the JWT, and know what permissions
        # this token has.
        iss: APP_IDENTIFIER
    }

    # Cryptographically sign the JWT
    jwt = JWT.encode(payload, PRIVATE_KEY, 'RS256')

where PRIVATE_KEY is set by

    PRIVATE_KEY = OpenSSL::PKey::RSA.new(ENV['GITHUB_PRIVATE_KEY'].gsub('\n', "\n")) # convert newlines

@tarebyte
Copy link
Member

@jqtruong out of curiosity, why are you converting the newlines?

@jqtruong
Copy link
Author

:) i'm just following orders... i mean instructions steps from the guide in this section.

@jqtruong
Copy link
Author

oh i guess it is useless in this code since it's already been converted in the environment variable.

@jqtruong
Copy link
Author

actually, nvm, that is needed because of the step in the guide. step replaces \n with the literal characters, and the code reverses that change, for a reason i do not quite understand at the moment. either way, the original issue still happens.

do you have any new thoughts that might help me? i'm willing to try anything at this point...

@jqtruong
Copy link
Author

closing, user error. i needed to specify the api_endpoint to my company's GHE... (facepalm)

@jakyns
Copy link

jakyns commented Mar 4, 2019

@jqtruong I have found this issue right now, could you explain how you add api_endpoint? 😅

@ctran
Copy link

ctran commented Mar 12, 2020

@jqtruong I have found this issue right now, could you explain how you add api_endpoint? 😅

Octokit.configure do |c|
  c.api_endpoint = "https://<hostname>/api/v3/"
end

@octokit octokit locked as resolved and limited conversation to collaborators Mar 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants