question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid VAPID token: A value in the vapid claims is either missing or incorrectly specified

See original GitHub issue

When 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:open
  • Created a year ago
  • Reactions:1
  • Comments:12

github_iconTop GitHub Comments

2reactions
sbodmercommented, Oct 21, 2022

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…

1reaction
atkawa7commented, Aug 3, 2022

@aistomin Yes that’s correct

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found