Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker Container: Could not authenticate via any gargle cred function #429

Open
kubussku opened this issue Jul 27, 2023 · 1 comment
Open
Assignees
Labels

Comments

@kubussku
Copy link

What goes wrong

Authenticating GA within docker container returns described error. authenticating works on local envir

Steps to reproduce the problem

dockerfile:

start from the rocker/r-ver:4.1.2 image

FROM rocker/r-ver:4.1.2

install the linux libraries needed for plumber

RUN apt-get update -qq && apt-get install -y
libssl-dev
libcurl4-gnutls-dev
libxml2-dev
libpq-dev
libproj-dev

install packs

RUN R -e "install.packages(c('googleAnalyticsR','googleAuthR'))"

copy everything from the current directory into the container

COPY / /

when the container starts, start the main.R script

ENTRYPOINT ["Rscript", "main.R"]

Expose the container to the host's network

CMD ["--network", "bridge"]


Obtain oauth token on local machine & save as file in rds

token = googleAuthR::gar_auth() # approach 1
token = googleAnalyticsR::ga_auth() # approach 2

saveRDS('gatoken.rds')

run container with main.r below

main.R
if (!require(googleAnalyticsR)) install.packages('googleAnalyticsR')
if (!require(googleAuthR)) install.packages('googleAuthR')

autpath = r'{authclient.json}' # service account
Sys.setenv(GARGLE_EMAIL = "name@mail.com")
googleAuthR::gar_set_client(authpath)

googleAnalyticsR::ga_auth(token = readRDS('gatoken.rds'))

Expected output

Authenticated Session within docker container

Actual output

✔ Setting client.id from authclient.json
[1] "name-name-123456"
ℹ 2023-07-27 18:13:35 > Using email from GARGLE_EMAIL env var: name@mail.com
Error: Could not authenticate via any gargle cred function
Execution halted

Before you run your code, please run:

options(googleAuthR.verbose=2) and copy-paste the console output here.
Check it doesn't include any sensitive info like auth tokens or accountIds - you can usually just edit those out manually and replace with say XXX
this does not give any more info

packages are matching. same applies to environment variables

@MarkEdmondson1234
Copy link
Collaborator

For a server-style authentication like when within docker, I suggest you use a service account key json file instead. There are various intricacies regarding OAuth2 HTTP requests that may be blocked in your docker settings you avoid then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants