firebase_admin icon indicating copy to clipboard operation
firebase_admin copied to clipboard

No access to ServiceAccountCredential class

Open lenzpaul opened this issue 5 years ago • 4 comments

I'm not sure whether the sample is outdated, but the first example on pub.dev doesn't seem to work. Even though I imported credentials.dart, even though I can see the ServiceAccountCredential class in the implementation file. I get undefined class whenever I try to use ServiceAccountCredential.

I followed install and import as per pub.dev. Also Flutter (or at least VSCode) doesn't seem to like the credentials.dart import.

lenzpaul avatar Aug 22 '20 22:08 lenzpaul

Did you try FirebaseAdmin.instance.certFromPath instead of ServiceAccountCredential ?

  var app = FirebaseAdmin.instance.initializeApp(AppOptions(
    credential: FirebaseAdmin.instance.certFromPath('service-account.json'),
  ));

akfaisel avatar Aug 25 '20 05:08 akfaisel

Did you try FirebaseAdmin.instance.certFromPath instead of ServiceAccountCredential ?

  var app = FirebaseAdmin.instance.initializeApp(AppOptions(
    credential: FirebaseAdmin.instance.certFromPath('service-account.json'),
  ));

Yes I have try again .. but file name too long error 36

ashishoffice avatar Dec 31 '20 20:12 ashishoffice

I created custom service-account.json manually and wrote there json directly.

final tempDir = await getTemporaryDirectory();
final file = File('${tempDir.path}/service-account.json');
final data = jsonEncode({ ... });  // source from original service-account.json
await file.writeAsString(data);
final credential = FirebaseAdmin.instance.certFromPath(file.path);
final adminApp = FirebaseAdmin.instance.initializeApp(
    AppOptions(
      credential: credential,
      projectId: projectId,
    ),
  );
}

eyelexv avatar Mar 06 '22 18:03 eyelexv

final tempDir = await getTemporaryDirectory(); final file = File('${tempDir.path}/service-account.json'); final data = jsonEncode({ ... }); // source from original service-account.json await file.writeAsString(data); final credential = Fi

@akfaisel I'm also having to do this to securely access the creds. I have mine stored as a cloud runtime variable, not locally in a .env or .json that gets built into the container. Since this is the most secure way to store the key for this context, I feel like it should be supported out of box - either by checking Platform.environment for GOOGLE_APPLICATION_CREDENTIALS or exposing ServiceAccountCredential.

solwey-wes avatar Jul 23 '23 03:07 solwey-wes