A micro-package to generate VAPID public and private keys and VAPID authorization headers, required for sending web push notifications. The library only supports VAPID-draft-02+ specification.
package main
import (
"fmt"
"github.com/AbdullahDiaa/govapid"
)
func main() {
//Generate VAPID keys
VAPIDkeys, err := govapid.GenerateVAPID()
if err != nil {
fmt.Println(err)
}
fmt.Printf("Public Key:%s\nPrivate Key:%s", VAPIDkeys.Public, VAPIDkeys.Private)
//Generate VAPID Authorization header which contains JWT signed token and VAPID public key
subURL, _ := url.Parse("https://fcm.googleapis.com/fcm/send/d5E6exZV5dM:APA91bHI09qFrkxTShu_pUVk-7ZukjdVhEJeZNUt29hSeBez93KlgXDK6Y9BThZMfWUqGhQ8yiWzYqT1gIGUxA5DVuwuARpJPSzk5XFp3yR1kepLKWOOdIgcAO6GRGoZYngmAFc6oufU")
claims := map[string]interface{}{
"aud": fmt.Sprintf("%s://%s", subURL.Scheme, subURL.Host),
"exp": time.Now().Add(time.Hour * 12).Unix(),
"sub": "mailto:[email protected]"}
AuthorizationHeader, _ := GenerateVAPIDAuth(VAPIDkeys, claims)
fmt.Println(AuthorizationHeader)
}
You can view detailed documentation here: GoDoc.
There are many ways to contribute:
View the changelog for the latest updates and changes by version.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.