Skip to content

Instantly share code, notes, and snippets.

@kdisneur
Forked from janakamarasena/secret_gen.rb
Created June 4, 2021 07:06
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 kdisneur/58d5459c1bad998f5c53120171bd8af6 to your computer and use it in GitHub Desktop.
Save kdisneur/58d5459c1bad998f5c53120171bd8af6 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment