什么是 VAPID,它为什么有用?

What is VAPID and why is it useful?

我最近才了解 VAPID,并一直在四处寻找它存在的原因及其目的。 Mozilla's blog post 解释说 "including VAPID information will let us contact you if we see a problem",但我不确定他们的意思。他们是否在进行某种监控以防止其他人模仿您的服务?

VAPID specification的摘要解释了一切:

An application server can voluntarily identify itself to a push service using the described technique. This identification information can be used by the push service to attribute requests that are made by the same application server to a single entity. This can used to reduce the secrecy for push subscription URLs by being able to restrict subscriptions to a specific application server. An application server is further able to include additional information that the operator of a push service can use to contact the operator of the application server.

所以VAPID有两个原因。

首先是将订阅的有效性限制在特定的应用服务器上(因此,通过使用 VAPID,只有您的服务器才能向订阅者发送通知)。

第二个是在推送通知中添加更多信息,以便推送服务运营商知道谁在发送通知。如果您的通知出现问题,接线员会知道您是谁并可以与您联系。此外,他们可以为您提供某种界面来监控您的推送通知。

您的 VAPID 密钥允许您的服务器向浏览器发送网络推送消息而无需使用 Firebase Cloud Messaging 或 AWS 等服务。

例如: Python 姜戈。您可以使用 Django-Webpush

pip3 安装django-webpush

https://pypi.org/project/django-webpush/