jwt generator

main
Laurent 2 years ago
parent 05201f8fea
commit fae034676a
  1. 6
      AuthKey_JZC9L76TDT.p8
  2. 1
      jwt_signed.txt
  3. 2
      pokeranalytics_backend/settings.py
  4. 54
      token_generator.py

@ -0,0 +1,6 @@
-----BEGIN PRIVATE KEY-----
MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgOzAYvVe2plgEO65I
rzpfDiorOSshVWOZyYyYxKukiMOgCgYIKoZIzj0DAQehRANCAATr5XT5byC/B3CD
3k5HZAVkcgnIpGIhLn/zcSoINnHpNoykKfNRcPAViyF5oPapP6dzdhzfXpPAschh
eKfajgao
-----END PRIVATE KEY-----

@ -0,0 +1 @@
eyJhbGciOiJFUzI1NiIsImtpZCI6IkpaQzlMNzZURFQiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiI2OWE2ZGU4My0wMmYyLTQ3ZTMtZTA1My01YjhjN2MxMWE0ZDEiLCJpYXQiOjE3MDUzMTQzMTYsImV4cCI6MTcwNTMxNzYxNiwiYXVkIjoiYXBwc3RvcmVjb25uZWN0LXYxIiwiYmlkIjoic3RheC5TbGFzaFBva2VyLm5vc2VibGVlZCJ9.3816SQjAWaFcsX-VRNLb7mHbx3EiqloqufIq9WB8oSSBlPs89H9rMdEvnq525ovYlNaoZIEnpsGPgHiPsWZAbA

@ -25,7 +25,7 @@ SECRET_KEY = 'django-insecure-v9l*b^t^2eqp877kdrt%5g#y=8$e%e^sa!65(1@t+rp@avwx+@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['*']
# Application definition

@ -0,0 +1,54 @@
import jwt
import datetime as dt
key_id = 'JZC9L76TDT'
alg = 'ES256'
typ = 'JWT'
issue_id = '69a6de83-02f2-47e3-e053-5b8c7c11a4d1'
aud = 'appstoreconnect-v1'
bid = 'stax.SlashPoker.nosebleed'
# Define issue timestamp.
issued_at_timestamp = int(dt.datetime.now().timestamp())
# Define expiration timestamp. May not exceed 20 minutes from issue timestamp.
expiration_timestamp = issued_at_timestamp + 55*60
# Define JWT headers.
headers = dict()
headers['alg'] = alg
headers['kid'] = key_id
headers['typ'] = typ
# Define JWT payload.
payload = dict()
payload['iss'] = issue_id
payload['iat'] = issued_at_timestamp
payload['exp'] = expiration_timestamp
payload['aud'] = aud
payload['bid'] = bid
# Path to signed private key.
KEY_FILE = 'AuthKey_JZC9L76TDT.p8'
with open(KEY_FILE,'r') as key_file:
key = ''.join(key_file.readlines())
client_secret = jwt.encode(
payload=payload,
headers=headers,
algorithm=alg,
key=key
)
with open('jwt_signed.txt', 'w') as output:
output.write(client_secret)
# Usage, after run this code by python3
# get token from `client_secret.txt` and replace to [signed token]
# Remember expired time maximum is 20 minutes
#
# curl -v -H 'Authorization: Bearer [signed token]' "https://api.storekit.itunes.apple.com/inApps/v1/notifications/test"
# curl -v -H 'Authorization: Bearer [signed token]' "https://api.storekit-sandbox.itunes.apple.com/inApps/v1/notifications/test"
#
# More detail https://developer.apple.com/documentation/appstoreconnectapi/generating_tokens_for_api_requests
Loading…
Cancel
Save