a-marenkov / gsheets

A Dart library for working with Google Sheets API.
Other
79 stars 31 forks source link

Different authentication approach #40

Closed jameswu0629 closed 3 years ago

jameswu0629 commented 3 years ago

Hi,

Now Gsheets only supports the credential from a json file, but in some cases we won't have a key file and have to use Autonomous Application / Compute Engine using metadata service (googleapis_auth)

import "package:googleapis_auth/auth_io.dart";

clientViaMetadataServer().then((AuthClient client) {
  // [client] is an authenticated HTTP client.
  // ...
  client.close();
});

Is that possible to use Gsheets if I don't have a key file?

a-marenkov commented 3 years ago

Hi,

Now Gsheets only supports the credential from a json file, but in some cases we won't have a key file and have to use Autonomous Application / Compute Engine using metadata service (googleapis_auth)

import "package:googleapis_auth/auth_io.dart";

clientViaMetadataServer().then((AuthClient client) {
  // [client] is an authenticated HTTP client.
  // ...
  client.close();
});

Is that possible to use Gsheets if I don't have a key file?

Hi, no, it's not supported currently.

However, I can add all auth options from googleapis_auth, so You'd be able to use clientViaMetadataServer

a-marenkov commented 3 years ago

Hi, no, it's not supported currently.

However, I can add all auth options from googleapis_auth, so You'd be able to use clientViaMetadataServer

I'll look into it

a-marenkov commented 3 years ago

@jameswu0629 can you please check version 0.2.7?

jameswu0629 commented 3 years ago

Hi @a-marenkov ,

I tried 0.2.7 but got the error message below:

$ dart run
Unhandled exception:
Access was denied (www-authenticate header was: Bearer realm="https://accounts.google.com/", error="insufficient_scope", scope="https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/drive.readonly https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/drive.resource https://www.googleapis.com/auth/spreadsheets https://spreadsheets.google.com/feeds https://spreadsheets.google.com/feeds/ http://spreadsheets.google.com/feeds http://spreadsheets.google.com/feeds/ https://spreadsheets.google.com/feeds/spreadsheets https://spreadsheets.google.com/feeds/spreadsheets/private/full http://spreadsheets.google.com/feeds/spreadsheets/private/full https://spreadsheets.google.com/feeds/worksheets/ https://spreadsheets.google.com/tq https://spreadsheets.google.com/feeds/list/ https://spreadsheets.google.com/feeds/worksheet/ https://spreadsheets.google.com/feeds/cell/ https://www.googleapis.com/auth/spreadsheets.readonly").
#0      AuthenticatedClient.send (package:googleapis_auth/src/auth_http_utils.dart:36:7)
<asynchronous suspension>
#1      BaseClient._sendUnstreamed (package:http/src/base_client.dart:91:32)
<asynchronous suspension>
#2      GSheets.spreadsheet (package:gsheets/src/gsheets.dart:191:22)
<asynchronous suspension>
#3      main (file:///home/xxxx/workspace/gsheets_test/bin/gsheets_test.dart:8:14)
<asynchronous suspension>

This is the sample code and I even set the spreadsheet as public:

import 'package:gsheets_test/gsheets_test.dart' as gsheets_test;

import 'package:gsheets/gsheets.dart';
import "package:googleapis_auth/auth_io.dart";

void main(List<String> arguments) async {
  final gsheets = GSheets.withClient(clientViaMetadataServer());
  final ss = await gsheets.spreadsheet('1E50pOghnhALp9f9A-qrlxKyISF-HOrlgttpFlMBbFqY');
}
a-marenkov commented 3 years ago

Hi @jameswu0629

To be honest i don't know much about auth with clientViaMetadataServer.

The error says insufficient_scope.

Have you tried to set scopes as it described here?

Also, if above doesn't help, it's better to address the question to https://github.com/dart-lang/googleapis/issues. I think googleapis team can assist on that and other auth options.

jameswu0629 commented 3 years ago

Have you tried to set scopes as it described here?

Yes, I did.

Also, if above doesn't help, it's better to address the question to https://github.com/dart-lang/googleapis/issues. I think googleapis team can assist on that and other auth options.

I will check with them.

Thank you for your help!

jameswu0629 commented 3 years ago

FYI: https://github.com/dart-lang/googleapis/issues/208