Skip to content

Instantly share code, notes, and snippets.

@ignitz
Last active January 23, 2020 13:21
Show Gist options
  • Save ignitz/5640b23bfc76914daf6dd393aedb898c to your computer and use it in GitHub Desktop.
Save ignitz/5640b23bfc76914daf6dd393aedb898c to your computer and use it in GitHub Desktop.
Template to generate JWT on Apple Store API
import jwt
from datetime import datetime
def get_token(authkey="privatekey.pem", ISSUER_ID = "UUID", KEY_ID = "KEYID"):
"""
Generater JSON Web Token from AppleStore API
"""
key = None
with open(authkey) as f:
key = f.read()
key
st_certd_jwt = jwt.encode(payload={
'iss': ISSUER_ID,
'exp': int(datetime.now().timestamp()) + 20 * 60,
'aud': "appstoreconnect-v1"
},
key=key,
headers={
'kid': KEY_ID },
algorithm='ES256')
return st_certd_jwt.decode()
require "base64"
require "jwt"
ISSUER_ID = "UUDI"
KEY_ID = "KEYID"
private_key = OpenSSL::PKey.read(File.read('AuthKey_XXXXXXXXXX.p8'))
token = JWT.encode(
{
iss: ISSUER_ID,
exp: Time.now.to_i + 20 * 60,
aud: "appstoreconnect-v1"
},
private_key,
"ES256",
header_fields={
kid: KEY_ID }
)
puts token
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment