Invalid VAPID token: A value in the vapid claims is either missing or incorrectly specified
See original GitHub issueWhen using this library I am getting Invalid VAPID token
. This occurs randomly sometimes you won’t get it at all. Sometimes you do.
[main] DEBUG *.*.*.PushService - header Authorization WebPush <jwt>
16:43:57.748 [main] DEBUG *.*.*.PushService - header Content-Encoding aesgcm
16:43:57.748 [main] DEBUG *.*.*.PushService - header Encryption salt=<salt>
16:43:57.748 [main] DEBUG *.*.*.PushService - header TTL 2419200
16:43:57.748 [main] DEBUG *.*.*.PushService - header Crypto-Key dh=BHGQ****dw=;p256ecdsa=BB_****
16:43:57.748 [main] DEBUG *.*.*.PushService - header Content-Type application/octet-stream
The response I am getting is
{"origin":"remote","type":"response","correlation":"b7b0107273db5d1e","duration":2227,"protocol":"HTTP/1.1","status":401,"headers":{"Connection":["keep-alive"],"Content-Length":["296"],"Content-Type":["application/json"],"Date":["Sat, 02 Jul 2022 14:44:00 GMT"],"Server":["nginx"]},"body":{"code":401,"errno":109,"error":"Unauthorized","message":"Invalid VAPID token: A value in the vapid claims is either missing or incorrectly specified (e.g. \"exp\":\"12345\" or \"sub\":null). Please correct and retry.","more_info":"http://autopush.readthedocs.io/en/latest/http.html#error-codes"}}
Subscription subscription = new Subscription();
subscription.endpoint = endpoint;
subscription.keys = new Keys();
subscription.keys.auth = auth;
subscription.keys.p256dh = p256dh;
ObjectMapper mapper = new ObjectMapper();
var webPushMessage = new WebPushMessage();
webPushMessage.setBody("A new document was uploaded");
webPushMessage.setTitle("Document uploaded");
var notification = new Notification(subscription, mapper.writeValueAsString(webPushMessage));
var logbook = createLogbook();
var client = httpClient(logbook);
var pushService = new PushService(keys.getPublicKey(), keys.getPrivateKey(), client);
pushService.send(notification);
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:12
Top Results From Across the Web
Using VAPID with WebPush | Mozilla Services
VAPID uses JSON Web Tokens (JWT) to carry identifying information. The core of the VAPID transaction is called a “claim”. A claim is...
Read more >Issues · web-push-libs/webpush-java - GitHub
Invalid VAPID token: A value in the vapid claims is either missing or incorrectly ... Does not handle non standard ports leading to...
Read more >[WebPush][VAPID] Request fails with 400 ... - Stack Overflow
The documentation speaks of different header usage for VAPID using Bearer/WebPush and using the Crypto-Key header or the Encryption-Key header. ...
Read more >Sending web push notifications in Safari and other browsers
Provide the VAPID JSON web token (JWT) and public key. ... The TTL header is either missing or isn't a positive number. BadUrgency....
Read more >The Web Push Protocol - web.dev
(This is defined by the VAPID spec.) ... Finally, the sub value needs to be either a URL or a mailto email address....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Bingo, I added the “sub” part and now it works, thanks a lot my friend ;^) I read the spec and the “sub” is not mandatory…
@aistomin Yes that’s correct