Skip to content

Instantly share code, notes, and snippets.

@ponnamkarthik
Created May 20, 2021 06:44
Show Gist options
  • Save ponnamkarthik/3e7a3dc7c0d4e7062f48266e89b36b97 to your computer and use it in GitHub Desktop.
Save ponnamkarthik/3e7a3dc7c0d4e7062f48266e89b36b97 to your computer and use it in GitHub Desktop.
Apple Signin REST
import time;
import requests;
import jwt;
TEAM_ID = ''
BUNDLE_ID = ''
KEY_FILE = './AuthKey_XXXX.p8'
ALG = 'ES256'
KID = ''
CODE_URL = 'https://appleid.apple.com/auth/token'
GRAND_TYPE = 'authorization_code'
AUD_URL = 'https://appleid.apple.com'
AUD_WS = 'appleid.apple.com'
VALIDITY_PERIOD = 180
DAY_SECOND = 86400
header = {'alg': ALG, 'kid': KID}
payload = {
'iss': TEAM_ID,
'iat': int(time.time()),
'exp': int(time.time() + DAY_SECOND * VALIDITY_PERIOD),
'aud': AUD_URL,
'sub': BUNDLE_ID
}
private_key = open(KEY_FILE).read()
client_sec = jwt.encode(payload=payload, key=private_key, algorithm=ALG, headers=header)
# .decode('utf-8')
post_data = {
'client_id': BUNDLE_ID,
'client_secret': client_sec,
'code': code,
'grant_type': GRAND_TYPE
}
login_req = requests.post(url=CODE_URL, data=post_data).json()
print(login_req)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment