Skip to content

Latest commit

 

History

History
72 lines (51 loc) · 2.57 KB

README.md

File metadata and controls

72 lines (51 loc) · 2.57 KB

GOVAPID

GoDoc codecov Build Status Go Report Card

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.

Usage

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)
}

Documentation

You can view detailed documentation here: GoDoc.

Contributing

There are many ways to contribute:

Changelog

View the changelog for the latest updates and changes by version.

License

Apache License 2.0

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.