Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for p8 files? #148

Open
jacksonkr opened this issue Mar 10, 2017 · 2 comments
Open

Support for p8 files? #148

jacksonkr opened this issue Mar 10, 2017 · 2 comments

Comments

@jacksonkr
Copy link

jacksonkr commented Mar 10, 2017

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
@justinkumpe
Copy link

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.

@SMillerDev
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants