No access to ServiceAccountCredential class
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.
Did you try FirebaseAdmin.instance.certFromPath instead of ServiceAccountCredential ?
var app = FirebaseAdmin.instance.initializeApp(AppOptions(
credential: FirebaseAdmin.instance.certFromPath('service-account.json'),
));
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
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,
),
);
}
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.