googlearchive / web-push-encryption

[Deprecated] Encryption Utilities for Web Push protocol
Apache License 2.0
84 stars 23 forks source link

Clarify what the subscription object should be in readme #19

Open owencm opened 8 years ago

owencm commented 8 years ago

It's unclear today what the subscription object in readme is supposed to be.

owencm commented 8 years ago

I.e. what keys should it have? How should they be encoded?

The question of how to get keys from a PushSubscription object on the client up to the server has turned out to be a big problem for me trying to get this to work and clarification would be great.

jonathanpmartins commented 8 years ago

@owencm you can find some explanation here: https://developers.google.com/web/updates/2016/03/web-push-encryption?hl=en Not sure, but I think the subscription object is the same that you get in registration.

jonathanpmartins commented 8 years ago

@owencm Looking more closely in the code I think the subscription object is somethin like this:

var subscription = {
    endpoint: '',
    keys: {
        p256dh: '',
        auth: ''
    }
};
bradennapier commented 8 years ago
 navigator.serviceWorker.ready.then(worker => {
      console.log('Service Worker is Ready')
      console.log(worker)
     worker.pushManager.getSubscription()
        .then(subscription => {
          console.log('Subscription: ', subscription)
          const sub = subscription || worker.pushManager.subscribe({userVisibleOnly: true})
          return sub
        }).then(sub => {
          const deviceSubscription = JSON.stringify(sub)
          // --> Send deviceSubscription to the Server
        }).catch(error => {
          console.error(error)
        })
})