googlePlayCredentials method

Future<GooglePlayCredentials> googlePlayCredentials()

Loads the service-account JSON.

Implementation

Future<GooglePlayCredentials> googlePlayCredentials() async {
  final value = _required(
    'SMF_GOOGLE_PLAY_SERVICE_ACCOUNT_JSON',
    'google-play-service-account-json',
  );
  try {
    final json = jsonDecode(value);
    SmfError.check(
      json is Map<Object?, Object?> &&
          json['type'] == 'service_account' &&
          _isNonEmptyString(json['client_id']) &&
          _isNonEmptyString(json['client_email']) &&
          _isNonEmptyString(json['private_key']),
      'Google Play credentials must be a complete service-account JSON '
      'document.',
      SmfErrorCode.invalidCredential,
    );
  } on FormatException catch (error) {
    throw SmfError(
      'Google Play service-account JSON is malformed.',
      SmfErrorCode.invalidCredential,
      cause: error,
    );
  }
  return GooglePlayCredentials(serviceAccountJson: value);
}