K
K
karpo5182020-01-28 16:14:53
PHP
karpo518, 2020-01-28 16:14:53

How to authenticate the VAPID public key on the server?

The js script on the client side stores the VAPID public key as a string, but sends it to the server by passing it through the urlBase64ToUint8Array function

urlBase64ToUint8Array Function
function urlBase64ToUint8Array(base64String) {
    const padding = '='.repeat((4 - (base64String.length % 4)) % 4);
    const base64 = (base64String + padding).replace(/\-/g, '+').replace(/_/g, '/');

    const rawData = window.atob(base64);
    const outputArray = new Uint8Array(rawData.length);

    for (let i = 0; i < rawData.length; ++i) {
      outputArray[i] = rawData.charCodeAt(i);
    }
    return outputArray;
  }

It is not clear how to match on the server the key from the settings and the key received in the request. The keys themselves are created using a php script https://github.com/web-push-libs/web-push-php/blob...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daria Motorina, 2020-01-28
@karpo518

The urlBase64ToUint8Array() function sends encrypted keys to a third-party server (on behalf of which notifications will be sent to the user's browser), and not to your server ( the demo code of the author of this package), you need to get these keys raw on the backend yourself (in fact - read from file). You do not need to convert the keys on the backend yourself, this is decided at the level of the vendor code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question