web-push-libs / webpush-java

Web Push library for Java
MIT License
315 stars 113 forks source link

403 Forbidden for Chrome #212

Open zhangms143 opened 4 months ago

zhangms143 commented 4 months ago

I'm trying to use web-push to push messages, and it works fine on Microsoft Chrome, but Google Chrome gets error 403 Forbidden.(Use the same key pair)

return message: the VAPID credentials in the authorization header do not correspond to the credentials used to create the subscriptions.

How do I fix it?

Thor-Erling commented 2 months ago

I had the same issue, and found a fix on the problem and replaced the code in the following lines

---- AbstractPushService.java ----
Line 211:  headers.put("Crypto-Key", headers.get("Crypto-Key") + ";p256ecdsa=" + Base64.getUrlEncoder().withoutPadding().encodeToString(pk));
Line 212:  headers.put("Crypto-Key", "p256ecdsa=" + Base64.getUrlEncoder().encodeToString(pk));