FirebaseServiceAccountCredentials.fromJson constructor

FirebaseServiceAccountCredentials.fromJson(
  1. Map<String, dynamic> json
)

Creates a new instance of FirebaseServiceAccountCredentials from a JSON map.

Expects the JSON to match the structure of the file downloaded from Firebase console.

Example:

{
  "type": "service_account",
  "project_id": "your-project-id",
  "private_key_id": "...",
  "private_key": "...",
  "client_email": "firebase-adminsdk-xxxxx@your-project-id.iam.gserviceaccount.com",
  "client_id": "...",
  ...
}

Implementation

factory FirebaseServiceAccountCredentials.fromJson(
  final Map<String, dynamic> json,
) {
  final projectId = json['project_id'] as String?;
  if (projectId == null || projectId.isEmpty) {
    throw const FormatException('Missing or empty "project_id"');
  }

  final clientEmail = json['client_email'] as String?;

  return FirebaseServiceAccountCredentials(
    projectId: projectId,
    clientEmail: clientEmail,
  );
}