createAuthClient static method
Creates an auth client for the google cloud environment.
If pathToServiceAccountJson
is provided, the client is created with the service account credentials.
Else the client is created with the application default credentials (e.g. from environment variables)
The scopes
need to be set, to the services you want to use. E.g. FirestoreApi.datastoreScope
.
Implementation
static Future<AuthClient> createAuthClient(
{required List<String> scopes, String? pathToServiceAccountJson}) async {
if (pathToServiceAccountJson == null) {
return await clientViaApplicationDefaultCredentials(scopes: scopes);
} else {
final serviceAccountJson =
jsonDecode(await File(pathToServiceAccountJson).readAsString());
final accountCredentials =
ServiceAccountCredentials.fromJson(serviceAccountJson);
return await clientViaServiceAccount(accountCredentials, scopes);
}
}