StackOverflow!
I'm attempting to send Web Push notifications from my Flask application using the pywebpush and py_vapid libraries for authentication with VAPID keys, but I'm encountering an error claiming that the aud field is missing from my VAPID claims.
Here is the code I'm using to send the notification:
from pywebpush import webpush, WebPushException
vapid_private_key_pem = "KE0RL_B2SY1AVcpHRWgTzC68or6cLC4RZaHmkM4ZsLk"
def send_push_notification(subscription_info, data):
vapid_claims = {
"sub": "mailto:[email protected]",
"aud": "https://chat.bitsquad.ru/"
}
try:
response = webpush(
subscription_info=subscription_info,
data=data,
vapid_private_key=vapid_private_key_pem,
vapid_claims=vapid_claims
)
print("Push sent successfully: ", response)
return True
except WebPushException as ex:
print("Web push failure: ", repr(ex))
return False
When attempting to execute this function, I receive the following error:
ValueError: Missing 'aud' from claims. 'aud' is the scheme, host and optional port for this transaction e.g. https://example.com:8080
To diagnose and correct the problem, I took several steps:
Double-checking VAPID claims: I re-checked the format and content of
vapid_claims, ensuring thataud,sub, and other necessary fields accurately met the specifications.Updating libraries: I made sure I was using the latest versions of the
pywebpushandpy_vapidlibraries to eliminate the possibility of errors due to outdated software.Logging: Directly before sending the notification, I added logging for key variables, including
vapid_claimsandsubscription_info, to ensure their correctness.Checking the private key format: I re-verified the format of my VAPID private key, ensuring it met the expected standards and was correctly used in the code.
Unfortunately, despite all my efforts, the "Missing 'aud' from claims" issue persists, and I'm reaching