'Issued at' claim ('iat') must be an Integer representing the time that the assertion was issued

I have a Github App on Github Enterprise 2.17. When I try to create an access token for my App using the JWT  for the first 4 or 5 seconds, it is rejected by the server with the error:

401 - ‘Issued at’ claim (‘iat’) must be an Integer representing the time that the assertion was issued // See: https://developer.github.com/enterprise/2.17/v3
After 4 seconds pass and several retries server accepts the JWT and returns an access token

I have a script demonstrating the behavior:

require 'json'
require 'openssl'
require 'octokit'
require 'jwt'
require 'time'
require 'pp'
require 'pry'


Octokit.configure do |c|
  c.api_endpoint = 'https://mygithubserver.com/api/v3/'
end


GITHUB_APP_ID = 2
GITHUB_APP_PRIVATE_KEY_FILE = 'github.app.pem'.freeze
GITHUB_INSTALLATION_ID = 4

payload = {
  iat: Time.now.to_i,
  exp: Time.now.to_i + (9 * 60),
  iss: GITHUB_APP_ID
}

# Cryptographically sign the JWT
private_pem = File.read(GITHUB_APP_PRIVATE_KEY_FILE)
private_key = OpenSSL::PKey::RSA.new(private_pem)
jwt = JWT.encode(payload, private_key, 'RS256')

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


begin
  installation_token = client.create_app_installation_access_token(GITHUB_INSTALLATION_ID, accept: 'application/vnd.github.machine-man-preview+json')[:token]
rescue Octokit::Unauthorized => e
  puts "ERROR: #{e}"
  sleep(1)
  retry
end

Is this the expected behavior? 

Looks like the systems’ clock was out of sync! The error is not so descriptive. I think it should be fixed!

Thanks for the update @nikosvlagoidis