Skip to content

Instantly share code, notes, and snippets.

@janakamarasena
Last active May 2, 2024 01:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save janakamarasena/cb1ebb4abec8c903329cb25ecb6fe562 to your computer and use it in GitHub Desktop.
Save janakamarasena/cb1ebb4abec8c903329cb25ecb6fe562 to your computer and use it in GitHub Desktop.
Sign In with Apple Client Secret Generator
require "jwt"
key_file = "Path to the private key"
team_id = "Your Team ID"
client_id = "The Service ID of the service you created"
key_id = "The Key ID of the private key"
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
@janakamarasena
Copy link
Author

janakamarasena commented Jun 10, 2019

Requires ruby

Also requires ruby-jwt
sudo gem install jwt

Add the necessary details and run the file.
ruby secret_gen.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment