Skip to content

Instantly share code, notes, and snippets.

@builtbyproxy
Last active July 23, 2020 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save builtbyproxy/20abff74cb6c1e45fcf806285720735a to your computer and use it in GitHub Desktop.
Save builtbyproxy/20abff74cb6c1e45fcf806285720735a to your computer and use it in GitHub Desktop.
require 'jwt'
key_file = 'key.txt' # This is the .p8 file you download from developer.apple.com. Just rename it to key.txt
team_id = ''
client_id = ''
key_id = '' # This is the KeyID of the .p8 file when you create it
ecdsa_key = OpenSSL::PKey::EC.new IO.read key_file
puts "Found Key"
puts IO.read key_file
puts "Encrypting"
headers = {
'kid' => key_id
}
claims = {
'iss' => team_id,
'iat' => Time.now.to_i,
'exp' => Time.now.to_i + 86400*180,
'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