From fae034676aac74a7dc5e742b9ffa8e7bb8eb0594 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 15 Jan 2024 11:41:19 +0100 Subject: [PATCH] jwt generator --- AuthKey_JZC9L76TDT.p8 | 6 ++++ jwt_signed.txt | 1 + pokeranalytics_backend/settings.py | 2 +- token_generator.py | 54 ++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 AuthKey_JZC9L76TDT.p8 create mode 100644 jwt_signed.txt create mode 100644 token_generator.py diff --git a/AuthKey_JZC9L76TDT.p8 b/AuthKey_JZC9L76TDT.p8 new file mode 100644 index 0000000..b74bd74 --- /dev/null +++ b/AuthKey_JZC9L76TDT.p8 @@ -0,0 +1,6 @@ +-----BEGIN PRIVATE KEY----- +MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgOzAYvVe2plgEO65I +rzpfDiorOSshVWOZyYyYxKukiMOgCgYIKoZIzj0DAQehRANCAATr5XT5byC/B3CD +3k5HZAVkcgnIpGIhLn/zcSoINnHpNoykKfNRcPAViyF5oPapP6dzdhzfXpPAschh +eKfajgao +-----END PRIVATE KEY----- \ No newline at end of file diff --git a/jwt_signed.txt b/jwt_signed.txt new file mode 100644 index 0000000..80e21bc --- /dev/null +++ b/jwt_signed.txt @@ -0,0 +1 @@ +eyJhbGciOiJFUzI1NiIsImtpZCI6IkpaQzlMNzZURFQiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiI2OWE2ZGU4My0wMmYyLTQ3ZTMtZTA1My01YjhjN2MxMWE0ZDEiLCJpYXQiOjE3MDUzMTQzMTYsImV4cCI6MTcwNTMxNzYxNiwiYXVkIjoiYXBwc3RvcmVjb25uZWN0LXYxIiwiYmlkIjoic3RheC5TbGFzaFBva2VyLm5vc2VibGVlZCJ9.3816SQjAWaFcsX-VRNLb7mHbx3EiqloqufIq9WB8oSSBlPs89H9rMdEvnq525ovYlNaoZIEnpsGPgHiPsWZAbA \ No newline at end of file diff --git a/pokeranalytics_backend/settings.py b/pokeranalytics_backend/settings.py index 7a03f16..58c36d1 100644 --- a/pokeranalytics_backend/settings.py +++ b/pokeranalytics_backend/settings.py @@ -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 diff --git a/token_generator.py b/token_generator.py new file mode 100644 index 0000000..84aa6df --- /dev/null +++ b/token_generator.py @@ -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