Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
github.com/mdigger/apns
Apple Push Notification service includes the APNs Provider API that allows you to send remote notifications to your app on iOS, tvOS, and OS X devices, and to Apple Watch via iOS. This API is based on the HTTP/2 network protocol. Each interaction starts with a POST request, containing a JSON payload, that you send from your provider server to APNs. APNs then forwards the notification to your app on a specific user device.
Your APNs certificate, which you obtain as explained in Creating a Universal Push Notification Client SSL Certificate in App Distribution Guide, enables connection to both the APNs Production and Development environments.
You can use your APNs certificate to send notifications to your primary app, as identified by its bundle ID, as well as to any Apple Watch complications or backgrounded VoIP services associated with that app.
package main
import (
"log"
"math/rand"
"time"
"github.com/mdigger/apns"
)
func main() {
cert, err := apns.LoadCertificate("cert.p12", "xopen123")
if err != nil {
log.Fatalln("Error loading certificate:", err)
}
client := apns.New(*cert)
id, err := client.Push(apns.Notification{
Token: `883982D57CDC4138D71E16B5ACBCB5DEBE3E625AFCEEE809A0F32895D2EA9D51`,
Payload: map[string]interface{}{
"aps": map[string]interface{}{
"alert": "Hello!",
"badge": rand.Int31n(99),
},
"time": time.Now().Format(time.RFC3339Nano),
},
})
if err != nil {
log.Fatalln("Error push:", err)
}
log.Println("Sent:", id)
}
You can use token-based authentication as an alternative to using provider certificates to connect to APNs. The provider API supports JSON Web Token (or JWT), an open standard, to pass authentication claims to APNs along with the push message.
package main
import (
"log"
"math/rand"
"time"
"github.com/mdigger/apns"
)
func main() {
providerToken, err := apns.NewProviderToken("W23G28NPJW", "67XV3VSJ95")
if err != nil {
log.Fatal(err)
}
err = providerToken.LoadPrivateKey("APNSAuthKey_67XV3VSJ95.p8")
if err != nil {
log.Fatal(err)
}
client := apns.NewWithToken(providerToken)
id, err := client.Push(apns.Notification{
Token: `883982D57CDC4138D71E16B5ACBCB5DEBE3E625AFCEEE809A0F32895D2EA9D51`,
Topic: "com.xyzrd.trackintouch",
Payload: map[string]interface{}{
"aps": map[string]interface{}{
"alert": "Hello, JWT!",
"badge": rand.Int31n(99),
},
"time": time.Now().Format(time.RFC3339Nano),
},
})
if err != nil {
log.Fatalln("Error push:", err)
}
log.Println("Sent:", id)
}
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.