Last active
June 8, 2020 05:35
-
-
Save sora0077/75b62f4a2a04480a90ef109a127ddbf5 to your computer and use it in GitHub Desktop.
This file contains 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
# setup | |
# pip install cryptography pyjwt | |
# ref. | |
# http://gobiko.com/blog/token-based-authentication-http2-example-apns/ | |
import jwt | |
import time | |
ALGORITHM = 'ES256' | |
KEY_ID = '' | |
AUTH_KEY = './AuthKey.p8' | |
TEAM_ID = '' | |
f = open(AUTH_KEY) | |
secret = f.read() | |
expires = 15770000 # 6 month | |
token = jwt.encode( | |
{ | |
'iss': TEAM_ID, | |
'iat': time.time(), | |
'exp': time.time() + expires | |
}, | |
secret, | |
algorithm= ALGORITHM, | |
headers={ | |
'alg': ALGORITHM, | |
'kid': KEY_ID, | |
} | |
) | |
print(token.decode('utf-8')) | |
#print(""" | |
#curl -v -H 'Authorization: Bearer %s' "https://api.music.apple.com/v1/catalog/us/songs/203709340" | |
#""" % token.decode('utf-8')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment