benwilkins / laravel-fcm-notification

Laravel FCM (Firebase Cloud Messaging) Notification Channel
MIT License
213 stars 91 forks source link

`401 The request was missing an Authentication Key #37

Open bigmosh opened 5 years ago

bigmosh commented 5 years ago

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: The request was missing an Authentication Key (FCM Token). Please, refer to section "Authentic (truncated...)</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/gdespiritorflex"><img src="https://avatars.githubusercontent.com/u/49168886?v=4" />gdespiritorflex</a> commented <strong> 4 years ago</strong> </div> <div class="markdown-body"> <p>+1 :(. </p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/smartraysam"><img src="https://avatars.githubusercontent.com/u/6819477?v=4" />smartraysam</a> commented <strong> 4 years ago</strong> </div> <div class="markdown-body"> <p>add Bearer before you key</p> <p>Authorization: Bearer your server key</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/MarcosSarges"><img src="https://avatars.githubusercontent.com/u/40393115?v=4" />MarcosSarges</a> commented <strong> 2 years ago</strong> </div> <div class="markdown-body"> <p>help <img src="https://user-images.githubusercontent.com/40393115/169529409-470562d9-0939-4992-bdd5-a5c79468e57b.png" alt="Screen Shot 2022-05-20 at 09 35 59" /> <img src="https://user-images.githubusercontent.com/40393115/169529421-e4bd510a-74eb-490c-b761-e68ba4e8ad51.png" alt="Screen Shot 2022-05-20 at 09 36 12" /></p> <h1>MY SOLUTION -> NODEJS</h1> <pre><code>(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); } })(); </code></pre> </div> </div> <div class="page-bar-simple"> </div> <div class="footer"> <ul class="body"> <li>© <script> document.write(new Date().getFullYear()) </script> Githubissues.</li> <li>Githubissues is a development platform for aggregating issues.</li> </ul> </div> <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script> <script src="/githubissues/assets/js.js"></script> <script src="/githubissues/assets/markdown.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/highlight.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/go.min.js"></script> <script> hljs.highlightAll(); </script> </body> </html>