Pr0Ger / PyAPNs2

Python library for interacting with the Apple Push Notification service (APNs) via HTTP/2 protocol
MIT License
349 stars 179 forks source link

Support for JWT authentication tokens #39

Closed shigmas closed 7 years ago

shigmas commented 7 years ago

This would make supporting multiple applications easier.

If it's alright, I'd like to add this. I don't know if it's overarchitecting, but I was thinking of replacing the cert_file parameter in APNsClient's init with a new Credentials class instance. There would be two subclasses: the CertificateCredentials and TokenCredentials. (Since tokens are meant to be reused (currently, for up to an hour), clients could come and go, as long as someone is holding on to the credentials instance.) Both classes would implement get_connection and get_authentication_header methods.

We could keep the old API too, and create the credential class if that parameter is a string:

def __init__(self, credentials, use_sandbox=False,...
...
    if isinstance(credentials, str):
      self.__credentials = CertificateCredentials(credentials)
   else:
      self.__credentials = credentials
shigmas commented 7 years ago

Am I off base? Is this a useless thing to support?

Pr0Ger commented 7 years ago

No, it's not. I had plans for adding support for tokens authentication but did not find some time for it. Thanks for your contribution, it's merged in ae835a195f5ed06004604503ecaf11d20cce6128

shigmas commented 7 years ago

Cool. Thanks!