0
votes

I'm trying to authenticate a Github app. I generated the JWT using Ruby script provided here.

I then ran this curl script as instructed:

curl -i -H "Authorization: Bearer YOUR_JWT" -H "Accept: application/vnd.github.machine-man-preview+json" https://api.github.com/app

I placed my JWT in the necessary place but it didn't work. I get a 401 response with the following message:

A JSON web token could not be decoded

Can anybody tell me what is wrong here?

1

1 Answers

1
votes

This is the Ruby script:

require 'openssl'
require 'jwt'  # https://rubygems.org/gems/jwt

# Private key contents
private_pem = File.read(YOUR_PATH_TO_PEM)
private_key = OpenSSL::PKey::RSA.new(private_pem)

# Generate the JWT
payload = {
  # issued at time
  iat: Time.now.to_i,
  # JWT expiration time (10 minute maximum)
  exp: Time.now.to_i + (10 * 60),
  # GitHub App's identifier
  iss: YOUR_ISSUE_NUMBER
}

jwt = JWT.encode(payload, private_key, "RS256")
puts jwt

It worked when I ncluded the YOUR_ISSUE_NUMBER in quotes. E.g. iss: "1234".