Repository navigation
feat(cli): init fcm with Google sign-in for the Appwrite Push FCM provider - #1956
ArnabChatterjee20k wants to merge 21 commits into
Conversation
🟢 Tier S · Ready to merge
Adds Latest changes: The newest commits enable Google APIs before checking permissions, surface enablement operation failures while allowing best-effort continuation, set IAM policy version 3, attribute key revocation to the selected project, and add clearer disabled-API guidance and regression tests.
📂 Walkthrough · 6
Reviewed the commits since |
…hout the Firebase Management API
What
appwrite init fcmsets up the FCM messaging provider that Appwrite Push uses to wake Android apps in the background. Developers no longer copy a service account key into the console by hand.The command can create the key itself: the developer signs in with Google through the Appwrite console, and the CLI makes a dedicated service account in their Firebase project and uploads its key.
init apnsandinit pushare in the stacked PR #1963, so this one can be released first.Run it from the app's root, in a directory linked with
appwrite init project.Flags
--key-path <file>.json)--project-id <id>google-services.json,lib/firebase_options.dartor.firebaserc. Otherwise a picker (from Google sign-in or thefirebaseCLI), or the key'sproject_id.--application-id <id>applicationIdin Gradle, or Expoandroid.package. With several apps, a picker.Global flags that matter here:
--force/-f--config-file <path>appwrite.config.json. Its folder is also searched for keys.Usage
Interactive, with Google sign-in
Key already in the project folder
appwrite init fcm # ℹ Info: Using sticker-smash-fb-firebase-adminsdk-x1.json from the project folder.CI
Rotating the key
How it works
Creating the key with Google
This works the same way as the console's one-click FCM setup (appwrite/vibes#514), using the console's existing Google sign-in. There's no separate OAuth app for the CLI.
Token: if the CLI's Appwrite account already has a Google identity with a live access token, it's reused. Otherwise the CLI opens
{endpoint}/account/tokens/oauth2/google?project=console&scopes[]=https://www.googleapis.com/auth/cloud-platform.GET /account/identitieswith its own session until a new Google token appears, for up to 5 minutes.Project: the CLI lists the user's Firebase projects (
firebase.googleapis.com/v1beta1/projects) and always asks which one gets the key, even when there's only one. A project ID detected from the app's config, or passed as--project-id, must be in the list and is used directly.Already set up? If the chosen project already has an enabled FCM provider and
--forceisn't passed, the CLI stops before creating anything.APIs:
serviceusageservices:batchEnableturns on the FCM, IAM and Cloud Resource Manager APIs in the chosen project, and the CLI polls the operation until it's done.Permissions:
testIamPermissionschecks foriam.serviceAccounts.create,iam.serviceAccountKeys.createandresourcemanager.projects.setIamPolicy.Key:
appwrite-fcm-xxxxxxxxservice account;roles/firebasecloudmessaging.adminthrough a version 3 IAM policy, retrying while the new account propagates;Every call bills the user's project (
X-Goog-User-Project), including revoking the key.Upload: the key is validated and uploaded straight into the provider, and never written to disk. If creating or updating the provider fails, the key is revoked.
Each blocker prints the reason and falls back to the browser or file options:
Where the key comes from otherwise
--key-path.appwrite.config.json, plus the folder the command runs in.project/_/when the project is unknown) and waits up to 15 minutes for the file in the project folder or~/Downloads.A key file inside a git repository that isn't git-ignored gets a warning to add it to
.gitignore.What it detects
com.android.application, and their application ID.google-services.json(module root and flavour folders), Expoandroid.package/googleServicesFile, Flutterlib/firebase_options.dart,.firebaserc.firebase-messagingdependency, with hints when they're missing.Checks before anything is sent
service_accountwith an RSA private key, and belong to the app's Firebase project.--force.Testing
initpush_test.go):cloud-platformscope) and a Google account that owns a Firebase project.Prerequisites for Google sign-in
The console's Google OAuth2 provider must allow the
cloud-platformscope, and the Firebase Management API must be enabled in the OAuth client's Google Cloud project. This is the same setup appwrite/vibes#514 needs. On a self-hosted server without it, the CLI falls back to the other options.Not in this PR
init apnsandinit push: stacked PR feat(cli): init apns and init push, with one-click APNs key creation #1963.validate_onlysend before upload.