This project consists of a Flutter frontend and a Firebase backend (Cloud Functions). Follow these steps to run install the dependencies and cloning the repository
Prerequisites
Ensure you have the following installed:
- Flutter SDK: Install Flutter (Version 3.x+)
- Node.js & npm: Install Node.js (Version 18 or 20 recommended for Firebase Functions)
- Firebase CLI:
npm install -g firebase-tools
- Salesforce Org: A Developer Edition org with a Connected App configured for OAuth
Google Cloud Platform Setup
Create Firebase project and enable services
- Go to the Firebase Console.
- Click Add project and follow the setup wizard.
- Once created, upgrade your project to the Blaze (Pay as you go) plan. This is required for Cloud Functions and Secret Manager.
- Go to Build > Authentication.
- Click Get Started.
- Enable Email/Password sign-in provider
- This project uses Custom Authentication (
signInWithCustomToken) to log users in after they authenticate with Salesforce. - You do not need to enable a specific “Custom” provider toggle in the console; the Admin SDK (used by Cloud Functions) handles this automatically.
- This project uses Custom Authentication (
- Go to Build > Firestore Database.
- Click Create Database.
- Choose a location (e.g.,
us-central1). - Start in Production mode.
- Note: The Flutter app requires the
cloud_firestoredependency (already included in pubspec.yaml) to interact with this database. - Go to Build > Functions.
- Click Get Started to initialize the service.
- Go to Build > Hosting.
- Click Get Started.
- Follow the on-screen instructions (you can skip the CLI install steps if you already have it)
- This service will host your Flutter Web application
Authorized Domains
For Flutter Web apps and OAuth redirects (like the Salesforce flow), you must whitelist the domains where your app is hosted. This prevents unauthorized sites from using your Firebase project’s authentication.
- Navigate to Settings:
- In the Authentication section, click on the Settings tab.
- Select Authorized domains.
- Add Domains:
Firebase automatically addslocalhostand your default Firebase hosting domains (project-id.firebaseapp.com,project-id.web.app). You need to add any other domains you use.- Local Development:
- Ensure
localhostis present (it usually is by default).
- Ensure
- Production / Custom Domains:
- If you host your app on a custom domain (e.g.,
www.myapp.com), click Add domain. - Enter your domain name.
- Click Add.
- If you host your app on a custom domain (e.g.,
- Salesforce Redirects:
- The Salesforce OAuth flow redirects back to your app. Ensure the domain hosting your
oauth2redirect.htmlfile is listed here. - For local dev:
localhostcovershttp://localhost:8686/oauth2redirect.html. - For production: Ensure your hosting domain is added.
- The Salesforce OAuth flow redirects back to your app. Ensure the domain hosting your
- Local Development:
Configure Secret Manager
The backend uses Google Cloud Secret Manager to securely store your Salesforce credentials
Login to Firebase with CLI
firebase login
Run these commands in your terminal to set the secrets. You will be prompted to enter the values from your Salesforce Connected App.
# Set the Salesforce Client ID
firebase functions:secrets:set client_id
# Set the Salesforce Client Secret
firebase functions:secrets:set client_secret
iOS and Android emulator setup
To run the Flutter app on mobile devices, you need to set up the respective emulators for iOS and Android.
Android Emulator
The Android Emulator is part of Android Studio.
Install Android Studio:
- Download and install Android Studio.
- During the setup wizard, ensure Android Virtual Device is selected.
- Create a Virtual Device (AVD):
- Open Android Studio and go to Device Manager (usually found under the “More Actions” menu on the welcome screen, or via Tools > Device Manager inside a project).
- Click Create Device.
- Select a hardware profile (e.g., Pixel 7).
- Select a System Image (e.g., API 34 or API 35). Download it if necessary.
- Click Finish.
- Start the Emulator:
- Click the Play button in the Device Manager to launch the emulator
iOS Simulator
The iOS Simulator is part of Xcode.
- Install Xcode:
- Download and install Xcode from the Mac App Store.
- Open Xcode once to accept the license agreement and install additional components.
- Open the Simulator:
- You can open it directly via Spotlight Search (Cmd + Space, type “Simulator”).
Verify detection
Run flutter devices in your terminal. You should see both the iOS and Android simulator. The emulators needs to started. You can also used flutter emulators command to list (and start) the emulators
Configuring environments (with environment.json)
The example.json file serves as a template or blueprint for your application’s configuration.
You need a “Connected App” in Salesforce to get these values.
- Log in to Salesforce Setup.
- Go to App Manager -> New Connected App.
- Enable OAuth Settings.
CLIENT_ID: Once the app is created, copy the Consumer Key. Paste it here.SCOPE: In the Connected App settings, add the scopes you need (e.g.,Access your basic information (id),Access and manage your data (api),Perform requests on your behalf at any time (refresh_token)). The string in your JSON must match these selections (space-separated).CALLBACK_URL_IOS_ANDROID: Define a custom URL for your mobile app (e.g.,salesforce.sample.app://oauth2redirect).CALLBACK_URL_WEB: Define a URL for the web flow (usually your Firebase Hosting URL +/oauth2redirect.html).- Important: You must paste BOTH of these URLs into the “Callback URL” field in your Salesforce Connected App settings (separated by a new line)
CLOUD_FUNCTIONS_BASE_URL- Deploy your functions using
firebase deploy --only functions. - Look at the terminal output or the Firebase Console (Functions tab).
- Copy the base URL (e.g.,
https://us-central1-your-project.cloudfunctions.net).
- Deploy your functions using
CUSTOM_URI_SCHEME:- This is the prefix of your mobile redirect URL (the part before
://). - In your example, it is
salesforce.sample.app. - Crucial: This string must match the URL Scheme defined in your iOS
Info.plistand AndroidAndroidManifest.xmlfiles, or the app won’t open after login.
- This is the prefix of your mobile redirect URL (the part before
AUTHORIZE_URL/TOKEN_URL:- The
{domain}placeholder indicates your code will dynamically swap this value. - Usually, you swap it with
loginfor Production ortestfor Sandbox. - If you use a custom domain (My Domain), you swap it with your company specific domain (e.g.,
mycompany).
- The

Leave a comment