I'm starting to use Web Push Notification; I don't know where I can find the auth key:
var pushSubscription = {
endpoint: '< Push Subscription URL >',
keys: {
p256dh: '< User Public Encryption Key >',
auth: '< ???? User Auth Secret ???? >'
}
};
I can get endpoint and p256dh from ServiceWorker>registeration.pushManager.getSubscription() but not the auth key.
Thanks
You can use the getKey method to get both p256dh and auth (see the specs or the example from the specs).
It's even simpler to just call JSON.stringify on the PushSubscription object returned by the getSubscription promise.
Using Typescript, the PushSubscription object should have a method on it called toJSON. Just use that.
const sub: PushSubscription = YOUR_RAW_PUSH_SUBSCRIPTION;
const pushSubscription = {
endpoint: sub.endpoint,
expirationTime: sub.expirationTime,
keys: {
p256dh: sub.toJSON().keys.p256dh,
auth: sub.toJSON().keys.auth
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With