r-lib / gargle

Infrastructure for calling Google APIs from R, including auth
https://gargle.r-lib.org/
Other
113 stars 33 forks source link

Creating pseudo OOB auth from DIY client #263

Closed meztez closed 1 year ago

meztez commented 1 year ago

Running

library(bigrquery)
bigrquery::bq_auth_configure(path = "extraw.json") #this function is obfuscated in internal data of package
gargle::cred_funs_set(list("credentials_user_oauth2" = gargle::cred_funs_list()$credentials_user_oauth2))

bigrquery::bq_auth(use_oob = TRUE)
con <- DBI::dbConnect(
  bigrquery::bigquery(),
  project = {project},
  dataset = {dataset},
  billing = {project},
  bigint = "numeric",
  quiet = FALSE
)

We hit Erreur 400 : redirect_uri_mismatch

We tracked it down to : https://github.com/r-lib/gargle/blob/237e03564888b3ef06419856f829c8f2ba0a3ece/R/Gargle-class.R#L85

there is something funky going on client_type and client$type, so params$oob_value end up null and not working.

We will replicate the function for now, until we can propose a better fix.

jennybc commented 1 year ago

Yeah I have found (and fixed) a bug in gargle 1.5.0. I'm doing some more checks to make sure I've got it right this time, then will do a patch release ASAP.

jennybc commented 1 year ago

I can't really release gargle until June 17, because I need to wait a week after the v1.5.0 release. But in the meantime, you could roll back to v1.4.0 or install the dev version. If you install the dev version, I'd love to hear confirmation that everything is fixed for you.

meztez commented 1 year ago

Sorry I did not share. We already had a workaround for bigrquery auth in place. Thanks for looking this up.

oauthfunction <- function (scopes = NULL, client = app, package = "gargle", ..., app = NULL) {
  gargle::gargle2.0_token(client = client, scope = scopes, package = package, app = client, ...)
}
gargle::cred_funs_set(list("credentials_user_oauth2" = oauthfunction))

@jennybc I've tested with 1.5.0.9000, the issue is gone. Auth works as expected. Thanks