You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -55,6 +65,17 @@ final app = FirebaseApp.initializeApp();
55
65
56
66
This will automatically initialize the SDK with [Google Application Default Credentials](https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application). Because default credentials lookup is fully automated in Google environments, with no need to supply environment variables or other configuration, this way of initializing the SDK is strongly recommended for applications running in Google environments such as Firebase App Hosting, Cloud Run, App Engine, and Cloud Functions for Firebase.
57
67
68
+
To optionally specify initialization options, use the `FIREBASE_CONFIG` environment variable. If the content begins with `{` it will be parsed as a JSON object, otherwise it is treated as a path to a JSON file containing the options:
// Options are read automatically from FIREBASE_CONFIG
76
+
final app = FirebaseApp.initializeApp();
77
+
```
78
+
58
79
### Initialize the SDK in non-Google environments
59
80
60
81
If you are working in a non-Google server environment in which default credentials lookup can't be fully automated, you can initialize the SDK with an exported service account key file.
@@ -77,6 +98,94 @@ The following `Credential` constructors are available:
77
98
-`Credential.fromServiceAccount(File)` — Loads credentials from a service account JSON file downloaded from the Firebase Console.
78
99
-`Credential.fromServiceAccountParams({required String privateKey, required String email, required String projectId, String? clientId})` — Builds credentials from individual service account fields directly.
79
100
101
+
#### Using Workload Identity Federation
102
+
103
+
[Workload Identity Federation](https://cloud.google.com/iam/docs/workload-identity-federation) lets external workloads (such as GitHub Actions, AWS, or Azure) authenticate as a Google service account without a long-lived key file.
104
+
105
+
Once your WIF credential configuration file is generated, point `GOOGLE_APPLICATION_CREDENTIALS` to it:
Then initialize the SDK with ADC, providing the impersonated service account email via `serviceAccountId`. This is required because WIF credential configs do not embed a `client_email` field, unlike service account key files:
In most cases, you only have to initialize a single default app:
127
+
128
+
```dart
129
+
// Initialize the default app
130
+
final defaultApp = FirebaseApp.initializeApp();
131
+
132
+
print(defaultApp.name); // '[DEFAULT]'
133
+
134
+
// Access services from the default app
135
+
final defaultAuth = defaultApp.auth();
136
+
final defaultFirestore = defaultApp.firestore();
137
+
```
138
+
139
+
Some use cases require multiple app instances at the same time — for example, reading data from one Firebase project and creating custom tokens for another, or authenticating two apps with separate credentials:
140
+
141
+
```dart
142
+
// Each AppOptions points to a different Firebase project
When testing locally with Google Application Default Credentials obtained via `gcloud auth application-default login`, you must explicitly provide a project ID because Firebase Authentication does not accept gcloud end-user credentials without one:
Once you have initialized an app instance with a credential, you can use any of the [supported services](#supported-services) to interact with Firebase.
0 commit comments