Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No access to ServiceAccountCredential class #8

Open
lenzpaul opened this issue Aug 22, 2020 · 4 comments
Open

No access to ServiceAccountCredential class #8

lenzpaul opened this issue Aug 22, 2020 · 4 comments

Comments

@lenzpaul
Copy link

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.

@akfaisel
Copy link

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

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

@ashishoffice
Copy link

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

@eyelexv
Copy link

eyelexv commented Mar 6, 2022

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,
    ),
  );
}

@solwey-wes
Copy link

solwey-wes commented Jul 23, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants