GoogleChromeLabs / web-push-codelab

Other
556 stars 291 forks source link

Explanation on public server key #47

Closed tomasdev closed 7 years ago

tomasdev commented 7 years ago

Hi,

I'm trying to figure out where does the server key come from at https://developers.google.com/web/fundamentals/getting-started/codelabs/push-notifications/#get_application_server_keys

Reason is I have a FCM key but it's not compatible with the 'to base 64 encoding' function.

tomasdev commented 7 years ago

Nevermind, found the answer at https://github.com/GoogleChrome/push-notifications/blob/master/companion-site/static/scripts/application-server-key.js#L64 via https://developers.google.com/web/fundamentals/engage-and-retain/push-notifications/subscribing-a-user#how_to_create_application_server_keys

return crypto.subtle.generateKey({name: 'ECDH', namedCurve: 'P-256'},
    true, ['deriveBits'])
  .then((keys) => {
    return cryptoKeyToUrlBase64(keys.publicKey, keys.privateKey);
  });