firebase/quickstart-js

[Firebase Cloud Messaging Quickstart] Should be updated to use Firebase Cloud Messaging API (V1)

visuallization opened this issue · 0 comments

Step 1: Describe your environment

  • Operating system: maxOS Ventura
  • Browser: Chrome
  • Firebase SDK version: 9.18.0

Step 2: Describe the problem:

As Firebase Cloud Messaging API (V1) is now enabled by default, the tutorial does not work anymore out of the box with the new API as there won't be a server key to use. You can still follow the tutorial though if you enable the Cloud Messaging API (Legacy) but this would need to be documented.

Steps to reproduce:

  1. Follow the tutorial in [quickstart-js/messaging](https://github.com/firebase/quickstart-js/messaging/)
  2. See the curl request will throw the error INVALID_KEY or PROJECT_NOT_PERMITTED

Observed Results:

Running the proposed command:

curl -X POST -H "Authorization: key=YOUR-SERVER-KEY" -H "Content-Type: application/json" -d '{
  "notification": {
    "title": "Portugal vs. Denmark",
    "body": "5 to 1",
    "icon": "firebase-logo.png",
    "click_action": "http://localhost:8081"
  },
  "to": "YOUR-IID-TOKEN"
}' "https://fcm.googleapis.com/fcm/send"

will throw the error INVALID_KEY or PROJECT_NOT_PERMITTED

Expected Results:

Have 2 messaging examples. One working with Cloud Messaging API (Legacy) and the other working with Firebase Cloud Messaging API (V1). Provide enough relevant information to make the examples work out of the box.

Relevant Code:

Follow the instructions in [quickstart-js/messaging](https://github.com/firebase/quickstart-js/messaging/) with a new Firebase project.

Run:

curl -X POST -H "Authorization: key=YOUR-SERVER-KEY" -H "Content-Type: application/json" -d '{
  "notification": {
    "title": "Portugal vs. Denmark",
    "body": "5 to 1",
    "icon": "firebase-logo.png",
    "click_action": "http://localhost:8081"
  },
  "to": "YOUR-IID-TOKEN"
}' "https://fcm.googleapis.com/fcm/send"

See it returns INVALID_KEY or PROJECT_NOT_PERMITTED.

If anyone else comes across this issue: This medium article helped me making Firebase Cloud Messaging API (V1) work: https://apoorv487.medium.com/testing-fcm-push-notification-http-v1-through-oauth-2-0-playground-postman-terminal-part-2-7d7a6a0e2fa0