Credential.fromApplicationDefaultCredentials constructor

Credential.fromApplicationDefaultCredentials({
  1. String? serviceAccountId,
})

Log in to firebase using the environment variable.

Implementation

factory Credential.fromApplicationDefaultCredentials({
  String? serviceAccountId,
}) {
  ServiceAccountCredentials? creds;

  final env =
      Zone.current[envSymbol] as Map<String, String>? ?? Platform.environment;
  final maybeConfig = env['GOOGLE_APPLICATION_CREDENTIALS'];
  if (maybeConfig != null) {
    try {
      final decodedValue = jsonDecode(maybeConfig);
      if (decodedValue is Map) {
        creds = ServiceAccountCredentials.fromJson(decodedValue);
      }
    } on FormatException catch (_) {}
  }

  return Credential._(
    creds,
    serviceAccountId: serviceAccountId,
  );
}