Created
June 22, 2018 13:44
-
-
Save BrandonSmith/4b7038d6ebc9146931b7b0a9cadac352 to your computer and use it in GitHub Desktop.
fcm-apns-debugging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
curl=/usr/local/opt/curl/bin/curl | |
openssl=/usr/local/opt/openssl/bin/openssl | |
deviceToken=TOKEN | |
authKey="./AuthKey_##########.p8" | |
authKeyId=########## | |
teamId=########## | |
bundleId=$$$$$$$$$$$$$$ | |
endpoint=https://api.development.push.apple.com | |
#endpoint=https://api.push.apple.com | |
read -r -d '' payload <<-'EOF' | |
{ | |
"aps": { | |
"badge": 0, | |
"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) | |
jwt="$header.$claims.$(sign $header.$claims)" | |
$curl --verbose \ | |
--header "content-type: application/json" \ | |
--header "authorization: bearer $jwt" \ | |
--header "apns-topic: $bundleId" \ | |
--data "$payload" \ | |
$endpoint/3/device/$deviceToken |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var { google } = require('googleapis') | |
function getAccessToken() { | |
return new Promise(function(resolve, reject) { | |
var key = require('./firebase-adminsdk-#####-##########.json'); | |
var jwtClient = new google.auth.JWT( | |
key.client_email, | |
null, | |
key.private_key, | |
['https://www.googleapis.com/auth/firebase.messaging'], | |
null | |
); | |
jwtClient.authorize(function(err, tokens) { | |
if (err) { | |
reject(err); | |
return; | |
} | |
resolve(tokens.access_token); | |
}); | |
}); | |
} | |
getAccessToken().then(console.log) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "fcm-apns-debugging", | |
"version": "1.0.0", | |
"description": "", | |
"main": "token.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Brandon Smith <[email protected]> (http://16cards.com/)", | |
"license": "ISC", | |
"dependencies": { | |
"googleapis": "~32.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment