Repository Public
1#!/usr/bin/env python32# =============================================================================3# SP BOUCHER | SOFTWARE & RESEARCH4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project : QYVORA8# File : App/Scripts/asc.py9# Module : Scripts10# Repository : https://git.spboucher.ai/qyvora11# Project Website : Not specified12# Created : 2026-12-0413# Last Modified : 2026-12-0414#15# Author : Simon-Pierre Boucher16# Position : Professor of Finance17# Institution : Université du Québec en Outaouais (UQO)18# Organization : SP Boucher19# Website : https://spboucher.ai20# Git : https://git.spboucher.ai21#22# Preferred Contact: contact@spboucher.ai23# Development : dev@spboucher.ai24# Support : support@spboucher.ai25# Security/Admin : admin@spboucher.ai26#27# Copyright (c) 202628# Simon-Pierre Boucher29# All rights reserved where applicable. This file is governed by the30# applicable project license, copyright notices and relevant law.31# Existing third-party rights and notices remain unaffected.32#33# License : None specified (no license file in this repository)34#35# Do not embed credentials, private keys, access tokens,36# certificates or confidential personal information.37#38# =============================================================================39# END OF SP BOUCHER SOURCE HEADER40# =============================================================================4142# QYVORA43# File: Scripts/asc.py44# Description: Minimal App Store Connect API client (JWT ES256 with the team key already on this Mac). Usage: asc.py GET /v1/apps?filter[bundleId]=…45#46# Author: Simon-Pierre Boucher47# Contact: contact@spboucher.ai48import base64, json, os, subprocess, sys, tempfile, time, urllib.request, urllib.error4950KEY_ID = os.environ.get("ASC_KEY_ID", "L379BDKR69")51ISSUER = os.environ.get("ASC_ISSUER_ID", "013e761f-e05c-4d93-a50b-f3d960adae4a")52KEY = os.path.expanduser(f"~/.appstoreconnect/private_keys/AuthKey_{KEY_ID}.p8")5354def b64(b): return base64.urlsafe_b64encode(b).rstrip(b"=")5556def token():57 head = b64(json.dumps({"alg": "ES256", "kid": KEY_ID, "typ": "JWT"}).encode())58 now = int(time.time())59 body = b64(json.dumps({"iss": ISSUER, "iat": now, "exp": now + 900, "aud": "appstoreconnect-v1"}).encode())60 msg = head + b"." + body61 with tempfile.NamedTemporaryFile() as f:62 f.write(msg); f.flush()63 der = subprocess.check_output(["openssl", "dgst", "-sha256", "-sign", KEY, f.name])64 # DER ECDSA signature -> raw r||s (JOSE)65 i = 2 if der[1] < 0x80 else 2 + (der[1] & 0x7F)66 rl = der[i + 1]; r = der[i + 2:i + 2 + rl]; i += 2 + rl67 sl = der[i + 1]; s = der[i + 2:i + 2 + sl]68 raw = r[-32:].rjust(32, b"\0") + s[-32:].rjust(32, b"\0")69 return (msg + b"." + b64(raw)).decode()7071def call(method, path, payload=None):72 req = urllib.request.Request("https://api.appstoreconnect.apple.com" + path, method=method, data=json.dumps(payload).encode() if payload is not None else None,73 headers={"Authorization": "Bearer " + token(), "Content-Type": "application/json"})74 try:75 with urllib.request.urlopen(req, timeout=60) as r: return r.status, json.loads(r.read() or b"{}")76 except urllib.error.HTTPError as e:77 return e.code, json.loads(e.read() or b"{}")7879if __name__ == "__main__":80 status, data = call(sys.argv[1], sys.argv[2], json.loads(sys.argv[3]) if len(sys.argv) > 3 else None)81 print(status); print(json.dumps(data, indent=1, ensure_ascii=False)[:6000])82