Send Firebase Push Notifications with Google OAuth 2.0 Playground

Nil Seri
4 min readFeb 9, 2024

--

Use Google Developers’ OAuth 2.0 Playground to test sending push notifications without a backend project

Photo by Eric Tompkins on Unsplash

First of all, needless to say, you need your Gmail account. It must be the same account which has auth in your Firebase project.

To create a Firebase project in Google and implement push in your frontend project, you can follow the instructions under the title “Firebase Settings” and “Frontend Push Service Implementation” described in this post:

To use the playground, visit https://developers.google.com/oauthplayground/

Google Developers — OAuth 2.0 Playground

In the input field (where it says “Input your own scopes”), type in:

email, https://www.googleapis.com/auth/firebase.messaging

Click on “Authorize APIs” (which is now enabled after you type in):

Enter scope

You will be directed to choose your account (which you must also give authorization in your Firebase project):

Select your account for OAuth

Once more, you will be warned about what will be shared and privacy&policy (as also declared at the bottom in the previous screen) before your sign-in:

Click on “Continue”.

As you can see, access will be revoked after 7 days from the app to your account:

Click on “Allow”.

Now you will be routed to the main page, where “Authorization code” is filled.

Authorization Code

Click on “Exchange authorization code for tokens”:

Token Info

You will now see that Step 3 is expanded. Click on “List possible operations” button and scroll to “Firebase Cloud Messaging API v1 — Messages Projects” and click on it to expand and select:

Available Operations — Firebase Cloud Messaging API

When you click on Firebase API from available operations, “Request URI” is filled with an API url where you need to replace “{+parent}” with your “projects/myProject” in which myProject should be your “project short name” in Firebase. Do not forget to include “projects/” at the beginning.

Request URI
https://fcm.googleapis.com/v1/projects/myProject/messages:send

You can find your project’s short name in Firebase Console (which I tried to point out with a purple square drawn around it in the screenshot below).

Now back in your playground console, click “Enter request body” and copy paste (or upload from a file) your request body and click on “Close”. Here, I will be sending a push notification to a single device with its registration token:

Click on “Send the request” button.

Voilà! Here arrives your push notification (see it on the right top).

You can also post it as a cURL request after you get your Bearer token. Remember, we clicked on “Exchange authorization code for tokens” and on the right side under “Request / Response”, “access_token” was provided to us:

Token Info

Using this access_token (Do not forget to add “Bearer ” at the beginning of your token as token_type is Bearer — see green json fields in screenshot above):

curl -X POST -H "Authorization: Bearer XXX" -H "Content-Type: application/json" -d '{
"message":{
"token":"XYZ",
"notification":{
"title":"Hello",
"body":"This is a text message!"
}
}
}' https://fcm.googleapis.com/v1/projects/myProject/messages:send

Happy Coding!

--

--

Nil Seri

I would love to change the world, but they won’t give me the source code | coding 👩🏻‍💻 | coffee ☕️ | jazz 🎷 | anime 🐲 | books 📚 | drawing 🎨