Projetos
Ver no GitHub
SherClockHolmes/webpush-go
Sobre
Criptografia da Web Push API com suporte a VAPID.
Segurança e privacidadeCrescimento medido de estrelas
- em 24 h
- 0
- em 7 dias
- +1
- em 15 dias
- +2
- em 1 mês
- Coletando histórico
Variações líquidas em períodos sobrepostos, não totais diários. Medições ausentes ficam em branco. Estrelas indicam interesse, não qualidade.
README.md
Originalwebpush-go
Web Push API Encryption with VAPID support.
go get -u github.com/SherClockHolmes/webpush-go
Example
For a full example, refer to the code in the example directory.
package main
import (
"encoding/json"
webpush "github.com/SherClockHolmes/webpush-go"
)
func main() {
// Decode subscription
s := &webpush.Subscription{}
json.Unmarshal([]byte("<YOUR_SUBSCRIPTION>"), s)
// Send Notification
resp, err := webpush.SendNotification([]byte("Test"), s, &webpush.Options{
Subscriber: "[email protected]",
VAPIDPublicKey: "<YOUR_VAPID_PUBLIC_KEY>",
VAPIDPrivateKey: "<YOUR_VAPID_PRIVATE_KEY>",
TTL: 30,
})
if err != nil {
// TODO: Handle error
}
defer resp.Body.Close()
}
Auth Scheme
Due to inconsistencies in how different browsers have implemented the Web Push protocol, it is necessary to specify which VAPID authentication scheme to use.
vapid: The original scheme, used by Firefox and other browsers.webpush: The modern scheme, used by Chrome.
You can specify the scheme in the Options struct:
&webpush.Options{
AuthScheme: webpush.WebPush,
// ... other options
}
If no AuthScheme is specified, it will default to vapid.
Generating VAPID Keys
Use the helper method GenerateVAPIDKeys to generate the VAPID key pair.
privateKey, publicKey, err := webpush.GenerateVAPIDKeys()
if err != nil {
// TODO: Handle error
}
Development
- Install Go 1.11+
go mod vendorgo test
For other language implementations visit:
Explore projetos relacionados
Carregando…