Laurent 2 years ago
parent 2a9050324b
commit c9c5a157d8
  1. 2
      jwt_signed.txt
  2. 34
      subscriptions/views.py
  3. 2
      token_generator.py

@ -1 +1 @@
eyJhbGciOiJFUzI1NiIsImtpZCI6IkpaQzlMNzZURFQiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiI2OWE2ZGU4My0wMmYyLTQ3ZTMtZTA1My01YjhjN2MxMWE0ZDEiLCJpYXQiOjE3MDUzOTYxMjMsImV4cCI6MTcwNTM5OTY2MywiYXVkIjoiYXBwc3RvcmVjb25uZWN0LXYxIiwiYmlkIjoic3RheC5TbGFzaFBva2VyLm5vc2VibGVlZCJ9.58Gr-6SuOER_AzTSdc0Lj_qvwxe0RqyAnOBW8uUiirmW-ocwENIhEkoCU5zs6z4HUqVR2MsOZFrdiR1hYvC5pQ
eyJhbGciOiJFUzI1NiIsImtpZCI6IkpaQzlMNzZURFQiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiI2OWE2ZGU4My0wMmYyLTQ3ZTMtZTA1My01YjhjN2MxMWE0ZDEiLCJpYXQiOjE3MDU0MDkxNjEsImV4cCI6MTcwNTQxMjcwMSwiYXVkIjoiYXBwc3RvcmVjb25uZWN0LXYxIiwiYmlkIjoic3RheC5TbGFzaFBva2VyLm5vc2VibGVlZCJ9.BYF6iaxsFE1bDO4U3K7PB-hkhkWcbZdIvfAlq8HZyPTyUPddEufTExPH8oKnaxoZrC-wfYJTL-eNwz-1z9IJ2A

@ -4,8 +4,11 @@ from django.views.decorators.csrf import csrf_exempt
from .models import ASSNotification
from django.conf import settings
from appstoreserverlibrary.models.Environment import Environment
from appstoreserverlibrary.signed_data_verifier import VerificationException, SignedDataVerifier
from appstoreserverlibrary.api_client import AppStoreServerAPIClient, APIException
from appstoreserverlibrary.models.Environment import Environment
import requests
import json, jwt
import base64
@ -20,7 +23,10 @@ from OpenSSL.crypto import (
FILETYPE_PEM
)
from .validate_apple_storekit_2_jwt import get_validated_jwt_content
ROOT_CER_URL = "https://www.apple.com/certificateauthority/AppleRootCA-G3.cer"
G6_CER_URL = "https://www.apple.com/certificateauthority/AppleWWDRCAG6.cer"
root_cert_bytes: bytes = requests.get(ROOT_CER_URL).content
g6_cert_bytes: bytes = requests.get(G6_CER_URL).content
# import app_store_notifications_v2_validator as asn2
# from app_store_notifications_v2_validator import InvalidTokenError
@ -42,14 +48,26 @@ def test(request):
def app_store_webhook(request):
decoded = request.body.decode('utf-8')
json = get_validated_jwt_content(decoded)
fulljson = json.loads(decoded)
signedPayload = fulljson['signedPayload']
client = AppStoreServerAPIClient(private_key_bytes, key_id, issuer_id, bundle_id, environment)
verifier = SignedDataVerifier([root_cert_bytes, g6_cert_bytes], False, environment, bundle_id)
try:
# response = client.get_transaction_info(<txn-id>)
decoded_txn = verifier.verify_and_decode_signed_transaction(signedPayload)
print(decoded_txn)
type = data['notificationType']
notification = ASSNotification(
content=type,
)
notification.save()
type = json['notificationType']
except APIException as e:
print(e)
notification = ASSNotification(
content=type,
)
notification.save()
# Parse the JSON payload

@ -43,7 +43,7 @@ key=key
with open('jwt_signed.txt', 'w') as output:
output.write(client_secret)
# curl -X POST -v -H 'Authorization: Bearer eyJhbGciOiJFUzI1NiIsImtpZCI6IkpaQzlMNzZURFQiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiI2OWE2ZGU4My0wMmYyLTQ3ZTMtZTA1My01YjhjN2MxMWE0ZDEiLCJpYXQiOjE3MDUzOTYxMjMsImV4cCI6MTcwNTM5OTY2MywiYXVkIjoiYXBwc3RvcmVjb25uZWN0LXYxIiwiYmlkIjoic3RheC5TbGFzaFBva2VyLm5vc2VibGVlZCJ9.58Gr-6SuOER_AzTSdc0Lj_qvwxe0RqyAnOBW8uUiirmW-ocwENIhEkoCU5zs6z4HUqVR2MsOZFrdiR1hYvC5pQ' https://api.storekit-sandbox.itunes.apple.com/inApps/v1/notifications/test
# curl -X POST -v -H 'Authorization: Bearer eyJhbGciOiJFUzI1NiIsImtpZCI6IkpaQzlMNzZURFQiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiI2OWE2ZGU4My0wMmYyLTQ3ZTMtZTA1My01YjhjN2MxMWE0ZDEiLCJpYXQiOjE3MDU0MDkxNjEsImV4cCI6MTcwNTQxMjcwMSwiYXVkIjoiYXBwc3RvcmVjb25uZWN0LXYxIiwiYmlkIjoic3RheC5TbGFzaFBva2VyLm5vc2VibGVlZCJ9.BYF6iaxsFE1bDO4U3K7PB-hkhkWcbZdIvfAlq8HZyPTyUPddEufTExPH8oKnaxoZrC-wfYJTL-eNwz-1z9IJ2A' https://api.storekit-sandbox.itunes.apple.com/inApps/v1/notifications/test
# 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

Loading…
Cancel
Save