I found a python tutorial at:
http://http://gobiko.com/blog/token-based-authentication-http2-example-apns/
but unfortunately when I implement it starting with:
import json
import jwt
import time
from hyper import HTTPConnection
ALGORITHM = 'ES256'
APNS_KEY_ID = 'H6Q3X7RYZG'
APNS_AUTH_KEY = 'APNsAuthKey_H6Q3X7RYZG.p8'
TEAM_ID = 'GF9PQ87F68'
REGISTRATION_ID = '713d3a9f4d932ac824caf9373a2f182b2dfa710fb7b6214e3bd405ae1e32d0aa'
BUNDLE_ID = 'com.meditation.iPujaPro'
f = open(APNS_AUTH_KEY)
secret = f.read()
print(secret)
token = jwt.encode(
{
'iss': TEAM_ID,
'iat': time.time()
},
secret,
algorithm = ALGORITHM,
headers={
'alg': ALGORITHM,
'kid': APNS_KEY_ID
}
)
I get:
Traceback (most recent call last):
File "simpleNotification.py", line 26, in <module>
'kid': APNS_KEY_ID
File "/usr/lib64/python2.7/site-packages/jwt/api_jwt.py", line 56, in encode
json_payload, key, algorithm, headers, json_encoder
File "/usr/lib64/python2.7/site-packages/jwt/api_jws.py", line 98, in encode
key = alg_obj.prepare_key(key)
File "/usr/lib64/python2.7/site-packages/jwt/algorithms.py", line 226, in prepare_key
key = load_pem_private_key(key, password=None, backend=default_backend())
File "/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/serialization.py", line 20, in load_pem_private_key
return backend.load_pem_private_key(data, password)
File "/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/multibackend.py", line 305, in load_pem_private_key
return b.load_pem_private_key(data, password)
File "/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1084, in load_pem_private_key
password,
File "/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1253, in _load_key
self._handle_key_loading_error()
File "/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1325, in _handle_key_loading_error
raise ValueError("Could not unserialize key data.")
ValueError: Could not unserialize key data.