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

Make authentication smoother on GCP R notebooks #147

Open
MarkEdmondson1234 opened this issue Jun 7, 2019 · 1 comment
Open

Make authentication smoother on GCP R notebooks #147

MarkEdmondson1234 opened this issue Jun 7, 2019 · 1 comment

Comments

@MarkEdmondson1234
Copy link
Owner

There should be a way to detect if you are using via a Jupyter notebook, and auto-authenticate using gar_gce_auth() or similar. Also need to look at how non-cloud APIs like googleAnalyticsR best authenticate in notebooks as you can't use ga_auth()

MarkEdmondson1234 added a commit that referenced this issue Jun 7, 2019
@MarkEdmondson1234
Copy link
Owner Author

Non-cloud APIs can either upload an offline token, or use gcloud to issue a user token:

## in the terminal, issue this gcloud command specifying the scopes to authenticate with
gcloud auth application-default login --scopes=https://www.googleapis.com/auth/analytics.readonly

## access the URL, login and create a verification code, paste in console.

## view then copy-paste the access token, to be passed into the R function
gcloud auth application-default print-access-token
# ya29.GlsiB-p2XXXXzuipzlNa_tZfqGoWpyZCNqf3-pWaioy-2mGjnrRos22acXXXX_94LUBjohSmboc-15saPfXXXXphhIj4mj9hT

Then in R, use the new function gar_gce_auth_defult to turn it into the expected R token:

gar_gce_auth_default(<token-copy-pasted>, 
                      scopes = 'https://www.googleapis.com/auth/analytics.readonly',
                      cache_file = 'my_ga.auth')
                     
# use token to authenticate as you would normally with library
# set up auto-auth with googleAnalyticsR
Sys.setenv("GA_AUTH_FILE" = "my_ga.auth")

library(googleAnalyticsR)
#Successfully auto-authenticated via ./my_ga.auth

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

No branches or pull requests

1 participant