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.

Unable to send Push Notification

See original GitHub issue

Hey @MartijnDwars, while sending the Notification I’m getting the following error:

the key in the authorization header does not correspond to the sender ID 
used to subscribe to this user. Please ensure you are using the correct sender 
ID and server Key from the Firebase console.

Getting the same error from curl request:

curl "https://fcm.googleapis.com/fcm/send/c9QOiG7bkdc:APA91bEwwW7Qt088axeqO0n0GVzDnVbu5oWGIy8R5YTbx2qYFAKs1iwL3w0F6zjHE8zGv1xX1WTUG0LTDq-I8Z1Zu5Su-CYnmW9yao7VKvca3KZJoxzsPM2riDsDAjCb9x6Gfr_i395J" 
--request POST --header "TTL: 60" --header "Content-Length: 0" \
 --header "Authorization: key=AAAAZod_va4:APA91bGa76B43GWRtECRmuLV6qOXjI9I_ulPrhp4oIZM91d4tfGSRPdrAWqko4_HRD0bzGKs-AN_AUerBxcKoz9IQ5uzkuVmRFOKmdy22D9Buq6LPOqOosIJ8GIdIblX2oY67p7jUcdG"

I’ve generated VAPID keys using npm module. These are the keys:

Public Key:
BNqEgHEqLOmF_B5rAkjwbFiTr6k5HzthWYul3UmorHOKXeXubI1D0oRw-nMN30ju6KTle2b_q9vNY1LAFtCz9B8

Private Key:
LwhPxh4pWvVQuSOHrLHIyY3qDWihyaLofzfoKPwLxjI

The subscription object looks like this:

{
"endpoint":"https://fcm.googleapis.com/fcm/send/c9QOiG7bkdc:APA91bEwwW7Qt088axeqO0n0GVzDnVbu5oWGIy8R5YTbx2qYFAKs1iwL3w0F6zjHE8zGv1xX1WTUG0LTDq-I8Z1Zu5Su-CYnmW9yao7VKvca3KZJoxzsPM2riDsDAjCb9x6Gfr_i395J",
"userPublicKey":"BDxcO0vK8HjrlGAOHhlCBj75G21uuRlc64WQU/lf1KOKMvZ175sLLcpEPjaln3QvJK9a5idKKegvSjPbslbd8XA=",
"userAuth":"OXde8QZMgpvnN+05Dljhgw=="
}

This is the code that I’m using for sending Push Notification:

nl.martijndwars.webpush.Notification notification;
WebSubscription sub = new WebSubscription();
sub.setEndpoint("https://fcm.googleapis.com/fcm/send/c9QOiG7bkdc:APA91bEwwW7Qt088axeqO0n0GVzDnVbu5oWGIy8R5YTbx2qYFAKs1iwL3w0F6zjHE8zGv1xX1WTUG0LTDq-I8Z1Zu5Su-CYnmW9yao7VKvca3KZJoxzsPM2riDsDAjCb9x6Gfr_i395J");
sub.setAuth("OXde8QZMgpvnN+05Dljhgw==");
sub.setKey("BDxcO0vK8HjrlGAOHhlCBj75G21uuRlc64WQU/lf1KOKMvZ175sLLcpEPjaln3QvJK9a5idKKegvSjPbslbd8XA=");
try {
    PushService pushService;
    notification = new nl.martijndwars.webpush.Notification(
            sub.getEndpoint(),
            sub.getUserPublicKey(),
            sub.getAuthAsBytes(),
            wpNotification.getAlert().getBytes(),
            255);

    // Instantiate the push service with a GCM API key
    pushService = new PushService("AIzaSyDpFKofoaa-VCFAJGYbK6QBfIRW5n2_j9o");
    pushService.setPrivateKey(nl.martijndwars.webpush.Utils.loadPrivateKey("LwhPxh4pWvVQuSOHrLHIyY3qDWihyaLofzfoKPwLxjI"));
    pushService.setPublicKey(nl.martijndwars.webpush.Utils.loadPublicKey("BNqEgHEqLOmF_B5rAkjwbFiTr6k5HzthWYul3UmorHOKXeXubI1D0oRw-nMN30ju6KTle2b_q9vNY1LAFtCz9B8"));
    HttpResponse httpResponse = pushService.send(notification);
    InputStream resInputStream = httpResponse.getEntity().getContent();
    StringWriter writer = new StringWriter();
    IOUtils.copy(resInputStream, writer, "UTF-8");
    String result = writer.toString();
    System.out.println(result);
} catch (Exception e) {
    LOG.error(sourceMethod, "Send Message failure...", e);
}

Am I using the keys wrong with Web-Push Library?

From the web-app, registration happens as follows:

const applicationServerPublicKey = "BNqEgHEqLOmF_B5rAkjwbFiTr6k5HzthWYul3UmorHOKXeXubI1D0oRw-nMN30ju6KTle2b_q9vNY1LAFtCz9B8";
const applicationServerKey = urlB64ToUint8Array(applicationServerPublicKey);
registration.pushManager.subscribe({
    userVisibleOnly: true,
    applicationServerKey: applicationServerKey
}).then(function(subscription) {
    return registerUsingToken(subscription);
}).catch(function(error) {
    if (Notification.permission === 'denied') {
    logger.info('Permission for Notifications was denied');
    } else {
    logger.error('Unable to subscribe to push.', error);
    }
});

Any help is appreciated, Thanks

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
martijndwarscommented, Nov 6, 2019

Sorry, didn’t get the time to look into this. Were you able to resolve this issue? Could you share the solution (for those coming from Google)?

3reactions
kopaxcommented, Aug 17, 2020

I am in the same situation. Can you share the solution ? Next time?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Push Notification Issues: Common Errors & Fixes
Go to Settings > Privacy > Location Services and scroll through the list to locate the app. Make sure it says Always next...
Read more >
If your Apple devices aren't getting Apple push notifications
Learn what to do if your Apple devices don't see Apple push notifications when connected to a network.
Read more >
Failed to send Push Notification - Stack Overflow
I try to send a message, but get nothing. Although no fails, when printing the variable: $result. this returns "to" (I have no...
Read more >
Workspace ONE Hub unable to send push notification when ...
When Workspace ONE Hub services are enabled, sending notification to Hub app fails and errors out. This happens with Android and iOS devices....
Read more >
Push Notification Troubleshooting for Android - Braze
We recommend setting a breakpoint or logging to ensure that the FCM-generated push token is being sent to Braze. If a token is...
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