laravel-fcm-notification icon indicating copy to clipboard operation
laravel-fcm-notification copied to clipboard

`401 The request was missing an Authentication Key

Open bigmosh opened this issue 5 years ago • 3 comments

The package had been working fine until recently, with noticed on our production server.

full error description below.

Client error: POST https://fcm.googleapis.com/fcm/send resulted in a 401 The request was missing an Authentication Key (FCM Token). Please, refer to section "Authentication" of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server. response: <HTML> <HEAD> <TITLE>The request was missing an Authentication Key (FCM Token). Please, refer to section "Authentic (truncated...)

bigmosh avatar Apr 30 '19 10:04 bigmosh

+1 :(.

gdespiritorflex avatar Oct 18 '19 13:10 gdespiritorflex

add Bearer before you key

Authorization: Bearer your server key

smartraysam avatar Aug 26 '20 19:08 smartraysam

help Screen Shot 2022-05-20 at 09 35 59 Screen Shot 2022-05-20 at 09 36 12

MY SOLUTION -> NODEJS

(async () => {
  try {
    const body = {
      registration_ids: [FCM_TOKEN],
      data: {
        score: "5x1",
        time: "15:10",
      },
      notification: {
        title: "teste",
        body: "asf",
        subtitle: "asg",
      },
    };

    const http = axios.create({ baseURL: "https://fcm.googleapis.com/fcm" });

    const headers = {};
    headers["Content-Type"] = "application/json";
    headers["Authorization"] = `key=${process.env.AUTH_KEY_GOOGLE}`;
    http.defaults.headers.post = headers;

    const { data: res } = await http.post("/send", body);
    console.log(res);
  } catch (error) {
    console.log(error);
  }
})();

MarcosSarges avatar May 20 '22 12:05 MarcosSarges