jazzband / django-push-notifications

Send push notifications to mobile devices through GCM or APNS in Django.
MIT License
2.23k stars 605 forks source link

New Apple .p8 apns cert support? #455

Open IanGleeson opened 6 years ago

IanGleeson commented 6 years ago

Is it possible to add support for apples .p8 apns format? I've tried using it through fcm but received a InvalidApnsCredential error.

They're much easier to work with than .pem

jleclanche commented 6 years ago

This might be something that needs to be done in pyapns2

jwmann commented 4 years ago

I'm also having this issue. The current instructions linked refer to a p12 file and Apple doesn't give out p12 files anymore. https://github.com/jazzband/django-push-notifications/blob/master/docs/APNS.rst

I'm really not sure how I'm supposed to continue from this point

jwmann commented 4 years ago

Okay, so I figured out how to get a p12 file and boy let me tell you. There's no way I could've figured this out by myself.

I managed to find this lovely website: https://batch.com/doc/ios/advanced/general.html#_generating-the-p12-certificate

The screenshots are a bit old but the information is still valid.

Here's a quick instruction list for those interested:

  1. Open Keychain Access
  2. Select "Certificates" from the Category Sidebar (not "My Certificates")
  3. Select the "Apple Worldwide Developer Relations Certification Authority" certificate from the list on the right.
  4. Select the Menu "Keychain Access" from the top Menu bar.
  5. From that Menu go into the "Certificate Assistant" Sub Menu.
  6. Select "Request a Certificate from a Certificate Authority"
  7. Select the "Save to Disk" and fill in the Information. Continue until complete.
  8. Go to the Identifiers List page and Select your App (or create one)
  9. Scroll down to Push Notifications section and select "Configure" or "Edit"
  10. Upload your Signing Certificate that you just created.
  11. Continue along the process and download your "cert" file.
  12. Open your new Cert file and add it to your Keychain Access
  13. Select your Cert file from Keychain Access. You should be able to find it under "My Certificates"
  14. Right click the Cert file and Select Export "Apple Push Services: ..."
  15. Give it a password (remember this for later) and Press okay.
  16. You have your p12 file! Now you can follow these instructions

Hopefully this helps someone stuck in the same situation.

DataGreed commented 4 years ago

If I would like to add the p8 support to the lib, where is the best way to start?

DataGreed commented 4 years ago

Okay, so p8 seems to be supported now. The support was silently added in release 2.0.0 (I found it just looking at the sources).

To use p8 you need to set your settings something like this:

PUSH_NOTIFICATIONS_SETTINGS = {
        # "APNS_CERTIFICATE": - this seems to be NO longer needed, comment it out
        "APNS_AUTH_KEY_PATH": os.path.join(BASE_DIR, "your_cert.p8"),
        "APNS_AUTH_KEY_ID": "YOUR_AUTH_KEY",
        "APNS_TEAM_ID": "YOUR_TEAM_ID",
        "APNS_TOPIC": "YOUR_TOPIC", # usually same as device bundle name
        "APNS_USE_SANDBOX": True, #or false
        #"UPDATE_ON_DUPLICATE_REG_ID": True,
}
DataGreed commented 4 years ago

Would be awesome to add it to readme :)

ianlater commented 1 year ago

I've followed these instructions and it connects and immediately closes. Not sure how to debug this.

silviogutierrez commented 1 year ago

@ianlater : FYI mine also connected and immediately closed when using the CLI verification. But it did work just fine.