我正在使用 PyJwt 为苹果应用程序通知服务令牌身份验证生成和编码 JWT,这需要此处ES256
所述的签名算法。
self.server = settings.APNS_SERVER
self.algorithm = 'ES256'
PRIVATE_KEY = settings.APNS_PRIVATE_KEY
encoded_jwt = jwt.encode(
{'iss': settings.TEAM_ID, 'iat': time.time()},
PRIVATE_KEY,
algorithm=self.algorithm,
headers={'alg': self.algorithm, 'kid': settings.APNS_KEY_ID},
)
当以这种方式通过时,我收到以下错误:
encoded_jwt = jwt.encode(
File "/usr/local/lib/python3.9/site-packages/jwt/api_jwt.py", line 63, in encode
return api_jws.encode(json_payload, key, algorithm, headers, json_encoder)
File "/usr/local/lib/python3.9/site-packages/jwt/api_jws.py", line 114, in encode
signature = alg_obj.sign(signing_input, key)
File "/usr/local/lib/python3.9/site-packages/jwt/algorithms.py", line 423, in sign
der_sig = key.sign(msg, ec.ECDSA(self.hash_alg()))
TypeError: sign() missing 1 required positional argument: 'algorithm'
RS256
当我使用orHS256
签名算法时,这不会发生。
为什么会这样?