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

bq_auth() with ADC authentication yields "Error in if (self$params$as_header)" #336

Closed
jpryda opened this issue Jul 10, 2019 · 4 comments
Closed

Comments

@jpryda
Copy link

jpryda commented Jul 10, 2019

I'm having some trouble authenticating with my application default credentials - that it appears to find successfully - using bigrquery 1.2.0:

options(gargle_quiet = FALSE)

Sys.setenv(GOOGLE_APPLICATION_CREDENTIALS='/Users/X/.config/gcloud/application_default_credentials.json')
bq_auth()

Result:

trying token_fetch()
trying credentials_service_account()
Error: Argument 'txt' must be a JSON string, URL or file.
trying credentials_app_default()
file exists at ADC path: /Users/X/.config/gcloud/application_default_credentials.json
ADC cred type: authorized_user
src_bigquery(project = "my-project", dataset = "medical")

Result:

- Error in if (self$params$as_header) { : argument is of length zero

In versions < 1.2.0 I had circumnavigated this same error by assigning token$params$as_header to a boolean value:

if (!has_access_cred()) {
  token <- gargle::credentials_app_default("https://www.googleapis.com/auth/bigquery")
  token$params$as_header <- TRUE
  set_access_cred(token)
}

although bq_auth(token = token) now fails with the aforementioned error message.

@jpryda jpryda changed the title bq_auth() and ADCs yields Error in if (self$params$as_header) bq_auth() with ADC authentication yields "Error in if (self$params$as_header)" Jul 10, 2019
@jennybc
Copy link
Collaborator

jennybc commented Jul 14, 2019

I think this should be fixed now, if you install dev gargle from GitHub:

devtools::install_github("r-lib/gargle")

however, I don't have any user creds stored in this manner, so have not tested it personally. I'd appreciate hearing back from you, after you try this.

Note that this type of credential + storage method is semi-deprecated from the Google side:

r-lib/gargle#78 (comment)

https://cloud.google.com/sdk/gcloud/reference/auth/application-default/login

Note: Consider using a service account and the complementary gcloud auth activate-service-account to authorize access to Google Cloud Platform.

If you are using ADC in this way, you should probably also seriously consider switching to a service account token. I think that's going to have better support long-term by Google and gargle + bigrquery.

@jennybc
Copy link
Collaborator

jennybc commented Jul 14, 2019

Also, your credentials should be auto-discovered, so once we straighten the as_header issue out, you should not need to do auth explicitly yourself anymore.

@jpryda
Copy link
Author

jpryda commented Jul 14, 2019

Thanks, it does indeed work now, and noted on the service account!

The last thing to mention for others is a correction to gargle's Git URI:

devtools::install_github("r-lib/gargle")

@jennybc
Copy link
Collaborator

jennybc commented Jul 14, 2019

correction to gargle's Git URI:

Oh, right thanks. I'll fix that. It's bigrquery that lives below r-dbi, d'oh.

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

2 participants