Skip to content

Instantly share code, notes, and snippets.

@loveJesus
Last active July 20, 2022 16:17
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 loveJesus/3f41027f8cdb935aa5c22533dc646af3 to your computer and use it in GitHub Desktop.
Save loveJesus/3f41027f8cdb935aa5c22533dc646af3 to your computer and use it in GitHub Desktop.
Hallelujah - Generate apple oauth2 client id from p8 file
# For God so loved the world, that He gave His only begotten Son, that all who believe in Him should not perish but have everlasting life
# pip install pyjwt
import time
import jwt
SOCIAL_AUTH_APPLE_TEAM_ID_CHIRHO = '3....' # see on the membership page, aleluya
SOCIAL_AUTH_APPLE_PRIVATE_KEY_CHIRHO = """-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----""" # From the p8 file, aleluya
SOCIAL_AUTH_APPLE_KEY_ID_CHIRHO = '3...' # services id aleluya
CLIENT_ID_CHIRHO = 'com....' # services id not app id aleluya
time_now_chirho = int(time.time())
headers = {
'kid': SOCIAL_AUTH_APPLE_KEY_ID_CHIRHO
}
payload = {
'iss': SOCIAL_AUTH_APPLE_TEAM_ID_CHIRHO,
'iat': time_now_chirho,
'exp': time_now_chirho + (24*60*60*180),
'aud': 'https://appleid.apple.com',
'sub': CLIENT_ID_CHIRHO,
}
client_secret = jwt.encode(
payload,
SOCIAL_AUTH_APPLE_PRIVATE_KEY_CHIRHO,
algorithm='ES256',
headers=headers
)
print(client_secret) # Display what you would use for the oauth calls aleluya
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment