Skip to content

Instantly share code, notes, and snippets.

@mefarazath
Last active June 7, 2021 12:28
Show Gist options
  • Save mefarazath/2e7837c1a411bc69221c3b7fe908f5fa to your computer and use it in GitHub Desktop.
Save mefarazath/2e7837c1a411bc69221c3b7fe908f5fa to your computer and use it in GitHub Desktop.
require 'jwt'
# Your private key from Apple
key_file = 'key.txt'
# Your 10-character Team ID
team_id = ''
# Your Services ID, e.g. idp.applesignintest.com
client_id = ''
# 10-char Key ID value from the Keys section
key_id = ''
ecdsa_key = OpenSSL::PKey::EC.new IO.read key_file
headers = {
'kid' => key_id
}
claims = {
'iss' => team_id,
'iat' => Time.now.to_i,
'exp' => Time.now.to_i + 86400*180, # This will be valid for 180 days
'aud' => 'https://appleid.apple.com',
'sub' => client_id,
}
token = JWT.encode claims, ecdsa_key, 'ES256', headers
puts token
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment