ApnsPHP icon indicating copy to clipboard operation
ApnsPHP copied to clipboard

Support for p8 files?

Open jacksonkr opened this issue 7 years ago • 2 comments

Apple offers a never expiring p8 file you can use for signing to send push notifications.

Any chance this is in the works? I have a working shell script and a python script for this if that's helpful at all. I've attached the shell script.

#!/bin/bash

# Get curl with HTTP/2 and openssl with ECDSA: 'brew install curl openssl'
curl=/usr/local/opt/curl/bin/curl
openssl=/usr/local/opt/openssl/bin/openssl

# --------------------------------------------------------------------------

deviceToken=55555555555555555555555555555555555555555555555555

authKey="./APNsAuthKey.p8"
authKeyId=ABC123456789
teamId=ABC123456789
bundleId=com.domain.project
endpoint=https://api.development.push.apple.com

read -r -d '' payload <<-'EOF'
{
   "aps": {
      "badge": 2,
      "category": "mycategory",
      "alert": {
         "title": "my title",
         "subtitle": "my subtitle",
         "body": "my body text message"
      }
   },
   "custom": {
      "mykey": "myvalue"
   }
}
EOF

# --------------------------------------------------------------------------

base64() {
   $openssl base64 -e -A | tr -- '+/' '-_' | tr -d =
}

sign() {
   printf "$1"| $openssl dgst -binary -sha256 -sign "$authKey" | base64
}

time=$(date +%s)
header=$(printf '{ "alg": "ES256", "kid": "%s" }' "$authKeyId" | base64)
claims=$(printf '{ "iss": "%s", "iat": %d }' "$teamId" "$time" | base64)
signed=$(sign $header.$claims)
jwt="$header.$claims.$signed"

$curl --verbose \
   --header "content-type: application/json" \
   --header "authorization: bearer $jwt" \
   --header "apns-topic: $bundleId" \
   --data "$payload" \
   $endpoint/3/device/$deviceToken

jacksonkr avatar Mar 10 '17 16:03 jacksonkr

Any updates on this? using p8 files (APNS Key) is very useful as they never expire and one key can be used for all apps under your account instead of having a separate certificate for each app you wish to send notifications to.

justinkumpe avatar Oct 14 '20 00:10 justinkumpe

Since the company I work for wants to keep using ApnsPHP we added p8 support: https://github.com/M2mobi/ApnsPHP/releases/tag/2.0.0beta1

SMillerDev avatar Feb 05 '21 14:02 SMillerDev