Skip to content

Instantly share code, notes, and snippets.

@stevenselcuk
Created August 9, 2022 14:02
Show Gist options
  • Save stevenselcuk/551f44b35307a4316ded1cb6972431b6 to your computer and use it in GitHub Desktop.
Save stevenselcuk/551f44b35307a4316ded1cb6972431b6 to your computer and use it in GitHub Desktop.
Secret Generator for Apple Login
require "jwt"
key_file = "./AuthKey_SDFSD45323.p8"
team_id = "9937MYTBBA"
client_id = "org.stuff.myappp"
key_id = "A1240ASD8"
validity_period = 180 # In days. Max 180 (6 months) according to Apple docs.
private_key = OpenSSL::PKey::EC.new IO.read key_file
token = JWT.encode(
{
iss: team_id,
iat: Time.now.to_i,
exp: Time.now.to_i + 86400 * validity_period,
aud: "https://appleid.apple.com",
sub: client_id
},
private_key,
"ES256",
header_fields=
{
kid: key_id
}
)
puts token
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment