Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 3

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

Solved! Go to Solution.

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? 

2 Replies
Solution
Copilot Lvl 2
Message 2 of 3

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

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

Community Manager
Message 3 of 3

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

Thanks for the update @NikosVlagoidis 


Best,
AndreaG

Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!