Skip to content

Instantly share code, notes, and snippets.

@sora0077
Last active June 8, 2020 05:35
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sora0077/75b62f4a2a04480a90ef109a127ddbf5 to your computer and use it in GitHub Desktop.
Save sora0077/75b62f4a2a04480a90ef109a127ddbf5 to your computer and use it in GitHub Desktop.
# 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