How to use Google Secret Manager with Flutter

192

This is one way I use to authenticate with Secret Manager:

Add your google json file to path and then export GOOGLE_APPLICATION_CREDENTIALS=<YOUR_PATH_TO_JSON_FILE>

Then change to this code:

import 'package:googleapis/secretmanager/v1.dart';
...
final client await clientViaApplicationDefaultCredentials(
    scopes: [FirestoreApi.cloudPlatformScope]);
final api = SecretManagerApi(client);
final secrets = await api.projects.secrets.versions.access(<YOUR_SECRET_NAME>);
print(secrets.payload!.data.toString());
// print(utf8.decode(secrets.payload!.dataAsBytes));
...
Share:
192
Christian
Author by

Christian

Updated on January 03, 2023

Comments

  • Christian
    Christian over 1 year

    I am trying to use https://pub.dev/packages/googleapis and get a value from the SecretManagerApi.

    This is my current code but it doesn't even resolve.

    final secretVersion = await SecretManagerApi(Client())
              .projects
              .secrets
              .get("projects/myProjectId/secrets/mySec/versions/latest")
    

    so secretVersion never gets a value. What am I doing wrong?

  • Christian
    Christian about 2 years
    Thank you very much. I almost got it to work but realized, that clientViaApplicationDefaultCredentials doesn't seem to work on a Web-App. How can I get the required Client on Web?