Search code examples
push-notificationtelegramtelegram-api

What is the Base64url-encoded authentication secret that Telegram requires to subscribe to push notifications?


According to the Telegram docs, to subscribe to web push notifications, you need to pass the following:

A JSON-encoded object with the following keys:

  • endpoint: Absolute URL exposed by the push service where the application server can send push messages
  • keys: P-256 elliptic curve Diffie-Hellman parameters in the following object
    • p256dh: Base64url-encoded P-256 elliptic curve Diffie-Hellman public key
    • auth: Base64url-encoded authentication secret

What is the last key, auth is referring to?

This question is related but doesn't really answer my question.


EDIT: Here is some sample code to generate the keys per Wizou's solution.


Solution

  • As mentioned in the doc, payloads can also be encrypted using P-256 Elliptic Curve Diffie-Hellman when using web push.

    As per the linked RFC, this encryption requires a public key, and an authentication secret.

    In Section 3.2, the RFC specifies that you should generate this secret by providing a hard-to-guess sequence of 16 octets that is used for authentication of push messages. This SHOULD be generated by a cryptographically strong random number generator [RFC4086].