Googlesheets4 login in docker container

86 Views Asked by At

My aim is to be able to distribute an R script which uses googlesheets4, as a docker image, to my work colleagues. That complicates google authentication, as credentials_user_oauth2() will not open a browser on the host machine. Also I want to avoid use of service accounts for this, rather I want regular google user accounts to be used, as with credentials_user_oauth2().

What is the best way to achieve this for simplest user experience?

My colleagues will have gcloud cli installed, but i cant see a way to use tokens generated with gcloud auth print-identity-token. And i cant find a way of using gcloud cli to produce a json key for the user account, only seems to work for service accounts.

Another option, pretty unsatisfactory, would be to mount the gargle_oauth_cache folder from the host in the docker container. It would mean that user still has to install R and googlesheets4 on the host. A one liner to initiate the login. On OSX the cache is in ~/Library/Caches/gargle/, no idea where it will be on Linux Rocker container.

My script will be using the optparse library so I hope to be able to end up with something that can be ran like:

docker run -it myimagename -- Rscript myscriptpath --googletoken=$(gcloud auth print-identity-token)

0

There are 0 best solutions below