Generate OAuth 2.0 token to Access Firebase APIs using NodeJs and Google Service Account

To send a generate OAuth 2.0 token, you can use NodeJs. We’ll follow some steps to do that.

1. First select project setting icon and click on project setting.

2. Click on Service Accounts.

Select NodeJs and and Generate new private key. A JSON file will be downloaded. Keep this JSON file confidential. Never publish this JSON file in public.

Now you’re done from the firebase dashboard.

3. Install NodeJs if you don’t have on your system.

Install Google API

npm install googleapis

4. Now create a file with <your_file>.js extension and print your OAuth 2.0 token. We’ll need this OAuth 2.0 token to call google APIs.

In my case, I’ve named my file print_auth_token.js.

5. Now run your file with “node print_auth_token.js“.

6. Now you’ve generated your OAuth 2.0 token. You can use this OAuth token to access any Firebase API from your backend. I my case, I will use this OAuth token to send FCM. For example Look at the following code snippet.

If you are using your own notification then use the following.

Leave a Reply