Skip to content

Server Setup

HB-Hridoy edited this page May 26, 2026 · 4 revisions

πŸš€ Step-by-Step Guide: Setting Up Your FCM Sender Server

Follow these instructions carefully to configure and deploy your Google Apps Script as a secure Firebase Cloud Messaging (FCM) sender server.


πŸ› οΈ Step 1: Create a New Apps Script Project

1.1 Access Google Apps Script

Create New Project

1.2 Project Configuration

  • Rename your project to something recognizable (e.g., FCM Sender Server).
  • Navigate to the left sidebar and click on Project Settings (the gear icon βš™οΈ).
Project Settings

1.3 Expose the Manifest File

  • Check the box for Show "appsscript.json" manifest file in editor.
Enable Manifest

1.4 Configure OAuth Scopes

  • Return to the Editor tab and open the newly visible appsscript.json file.
  • Inside the file configuration, add the script external request field to your "oauthScopes".
  • Save the file.
"oauthScopes": [
  "https://www.googleapis.com/auth/script.external_request"
]
Update Manifest Fields

πŸ”‘ Step 2: Setup Script Credentials

2.1 Initialize Your Script

  • Open your main script file (usually Code.gs).
  • Paste your server script template into the editor.
  • Define your custom SECRET_KEY.
Initialize Script Variables

2.2 Retrieve Firebase Project Credentials

  • Navigate to the Firebase Console.
  • Click the gear icon next to "Project Overview" and select Project settings.
Firebase Settings

2.3 Extract Project ID

  • Copy your unique Project ID and paste it into the respective variable within your Apps Script code.
Copy Project ID

2.4 Access Service Accounts

  • Inside Firebase Project Settings, switch to the Service accounts tab.
Service Accounts Tab

2.5 Generate Private Key

  • Scroll down and click the Generate new private key button.
  • Confirm and download the resulting .json key file to your local machine.
Generate Private Key

2.6 Link Service Account to Script

  • Open the downloaded .json file, copy its entire contents, and paste it directly into the SERVICE_ACCOUNT object variable in your script.
Paste Service Account JSON

2.7 Run Setup Test

  • Double-check that all 3 critical variables (SECRET_KEY, PROJECT_ID, and SERVICE_ACCOUNT) are filled out, then Save the file.
  • Select the testSetup function from the top toolbar dropdown.
  • Click Run.
Run Test Setup Function

πŸ§ͺ Step 3: Authorize and Test Your Script

⚠️ Note: On your first execution, Google requires an explicit permissions review. Follow the bypass steps below.

3.1 Review Permissions

  • When the authorization dialog appears, click Review permissions.
Review Permissions Dialog

3.2 Advanced Options

  • Select your Google Account, then click on the Advanced link at the bottom of the prompt.
Click Advanced Link

3.3 Bypass Warning

  • Click the safety bypass link labeled Go to FCM Sender Server (unsafe).
Bypass Safe Mode Warning

3.4 Confirm Access

  • Review the requested permissions scopes and click Allow / Continue to grant execution rights.
Allow Account Access

πŸŽ‰ Test Verification Success

  • Check the execution log window at the bottom of your screen.
  • If the log displays FCM response: 400 β€’ Auth OK, your environment is fully authorized and properly linked to Firebase.
Successful Test Verification

🌐 Step 4: Web App Project Deployment

4.1 Initiate Deployment

  • Click the Deploy button in the top right corner.
  • Choose New deployment from the dropdown menu.
Create New Deployment

4.2 Select Deployment Type

  • Click the Gear icon next to Select type.
  • Choose Web app from the options list.
Select Web App Type

4.3 Configure Deployment Settings

Set up your parameters exactly as follows to ensure external accessibility:

  • Description: Add a short note (e.g., FCM Sender HTTP v1 API _V1.0.0).
  • Execute as: Set to Me (your-email).
  • Who has access: Set to Anyone.
  • Click Deploy.
Configure Permissions

πŸ“‹ Final Step

  • Your web server deployment is complete!
  • Copy the generated Web app URL from the screen. This URL will serve as your live API endpoint inside your extension configuration.
Copy Web App URL