Caio Oliveira
Caio Oliveira

Reputation: 804

How to test FCM using Postman/curl with Angular 8

I am trying to setup notification for my web application(Angular 8)using web-push.

I've already used angular service worker to successfully register the users endpoint, p256dh, and auth. It is on the database already.

My backend is Laravel, however, after setting up everything it didn't work. So I am trying to setup a "raw" request with postman to teste if the notification itself is working before troubleshooting the backend.

(Tutorial I followed for the frontend: https://blog.angular-university.io/angular-push-notifications/)

Here is the json on postman:

{
   "to": "<HERE GOES THE USERS p256dh>",
   "notification": {
    "body": "Hello",
    "title": "This is test message."
   }
}

Url: ~~POST ~~

With the following headers:

Authorization: key=4uAH6X9MLTQWYWuDuUjBDk5P8OHPmFLWF9FZJeDAZMo (I've tried users auth code and also my VAPID_PRIVATE_KEY
Content-Type: application/Json

And I got the following response:

sender is not authenticated.

EDIT: Tried : https://fcm.googleapis.com/fcm/send and got:

Invalid (legacy) Server-key delivered or Sender is not authorized to perform request.

What am I doing wrong? The result expected would be a notification even with the browser closed.

(I am testing o locahost and serving via angular-http-server , built with ng build --prod)

Upvotes: 0

Views: 1082

Answers (2)

Caio Oliveira
Caio Oliveira

Reputation: 804

I already tested using npms send-notification:

  web-push send-notification --endpoint=<url> [--key=<browser key>] [--auth=<auth secret>] [--payload=<message>] [--ttl=<seconds>] [--vapid-subject=<vapid subject>] [--vapid-pubkey=<public key url base64>] [--vapid-pvtkey=<private key url base64>] 

Now is problem with the backend, which I will try to fix.

Upvotes: 0

Derryl Thomas
Derryl Thomas

Reputation: 1568

As the fcm response indicates, it looks like you are using the legacy server key for authentication. Legacy server keys are much shorter than the new server keys.

To fix this, use server key if you already have one or click add server key to create one and use this instead of the legacy server key in your authorization header.

See this image for reference.

Upvotes: 1

Related Questions