Created
May 20, 2021 06:44
-
-
Save ponnamkarthik/3e7a3dc7c0d4e7062f48266e89b36b97 to your computer and use it in GitHub Desktop.
Apple Signin REST
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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