tidyverse / googledrive

Google Drive R API
https://googledrive.tidyverse.org/
Other
322 stars 47 forks source link

Authentication problems with service account on linux server #415

Closed sciordia closed 1 year ago

sciordia commented 1 year ago

Using the googleAuthR package I created a service account using the gar_setup_get_authenv() command in RStudio (on MacOSX). I saved the obtained JSON file ('googleauthr-auth-key.json') and uploaded it to my linux server.

I want to run googledrive and googlesheets4 from the server terminal with Ubuntu 20.14.

After installing r-base and the necessary packages ('googledrive', 'googlesheets4', etc.). I have used the JSON file of the service account to authenticate the google account with the command "drive_auth(path='./googleauthr-auth-key.json')" but when I run 'drive_ls()' or 'drive_find()' I get no result.

What am I doing wrong?.

Thanks.

sciordia commented 1 year ago

More information: When I insert the JSON file, I always get this message:

Waiting for authentication in browser.... Press Esc/Ctrl + C to abort /usr/bin/xdg-open: 869: www-browser: not found /usr/bin/xdg-open: 869: links2: not found /usr/bin/xdg-open: 869: elinks: not found /usr/bin/xdg-open: 869: links: not found /usr/bin/xdg-open: 869: lynx: not found /usr/bin/xdg-open:869: w3m: not found xdg-open: no method available to open 'https://accounts.google.com/o/oauth2/v2/auth?client_id=xxxxxxx-dpeg5tt0et3go5of2374d83ifevk5086.apps.googleusercontent.com&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&redirect_uri=http%3A%2F%2Flocalhost%3A1410%2F&response_type=code&statxxxxxxxxxxxxxxxxxxxxxx'.

But as I don't have a web browser on the server (everything is through terminal) even if I click on the link it opens in my local browser but it gives an error.

I have tried to install in text browser 'w3m' but when I do it now only appears: 'Waiting for authentication in browser....'.

jennybc commented 1 year ago

If you successfully auth as the service account, one reason for unexpected results with, e.g. drive_ls() is that you are expecting to see files available to you, but what you will see is files available to the service account.

You can find out who you are auth'ed as with drive_user().

The second comment (about "waiting for authentication in browser") makes it sound like you have not successfuly auth'ed with the service account and, instead, have fallen through to the browser flow for a normal user. Which is doomed to fail if a browser cannot be launched.

I don't have enough information to offer any more diagnoses.