forked from pelauimagineering/apple-music-token-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
music_token.py
40 lines (28 loc) · 1.03 KB
/
music_token.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# requires pyjwt (https://pyjwt.readthedocs.io/en/latest/)
# pip install pyjwt
import datetime
import jwt
secret = """-----BEGIN PRIVATE KEY-----
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123
-----END PRIVATE KEY-----"""
keyId = "0123456789"
teamId = "9876543210"
alg = 'ES256'
time_now = datetime.datetime.now()
time_expired = datetime.datetime.now() + datetime.timedelta(hours=12)
headers = {
"alg": alg,
"kid": keyId
}
payload = {
"iss": teamId,
"exp": int(time_expired.strftime("%s")),
"iat": int(time_now.strftime("%s"))
}
if __name__ == "__main__":
"""Create an auth token"""
token = jwt.encode(payload, secret, algorithm=alg, headers=headers)
print "----TOKEN----"
print token
print "----CURL----"
print "curl -v -H 'Authorization: Bearer %s' \"https://api.music.apple.com/v1/catalog/us/artists/36954\" " % (token)