Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lib/src/util/google_cloud_helpers_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,20 @@ class GoogleCloudHelpers {
///
/// The [scopes] need to be set, to the services you want to use. E.g. `FirestoreApi.datastoreScope`.
static Future<AuthClient> createAuthClient(
{required List<String> scopes, String? pathToServiceAccountJson}) async {
if (pathToServiceAccountJson == null) {
{required List<String> scopes,
String? pathToServiceAccountJson,
String? serviceAccountJsonRaw}) async {
assert(!(pathToServiceAccountJson != null && serviceAccountJsonRaw != null),
'Only one of pathToServiceAccountJson or serviceAccountJson can be provided.');

if (pathToServiceAccountJson == null && serviceAccountJsonRaw == null) {
return await clientViaApplicationDefaultCredentials(scopes: scopes);
} else {
final serviceAccountJson =
jsonDecode(await File(pathToServiceAccountJson).readAsString());
final serviceAccountJson = pathToServiceAccountJson != null
? jsonDecode(await File(pathToServiceAccountJson).readAsString())
: serviceAccountJsonRaw != null
? jsonDecode(serviceAccountJsonRaw)
: null;

final accountCredentials =
ServiceAccountCredentials.fromJson(serviceAccountJson);
Expand Down
4 changes: 3 additions & 1 deletion lib/src/util/google_cloud_helpers_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ class GoogleCloudHelpers {

/// Just a stub for now. See google_cloud_helpers_dart.dart for documentation.
static Future<AutoRefreshingAuthClient> createAuthClient(
{required List<String> scopes, String? pathToServiceAccountJson}) async {
{required List<String> scopes,
String? pathToServiceAccountJson,
String? serviceAccountJsonRaw}) async {
throw UnimplementedError();
}

Expand Down