Search code examples
javascriptweb-pushweb-notifications

Javascript Web Push: where can I get "auth" key?


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


Solution

  • 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.