r-lib / gargle

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

Should `credentials_gce()` consult a named `email` argument in `...`? #249

Open jennybc opened 1 year ago

jennybc commented 1 year ago

Compare the typical signature of an auth function in an end-user package, like googledrive:

drive_auth <- function(email = gargle::gargle_oauth_email(),
                       path = NULL,
                       scopes = "https://www.googleapis.com/auth/drive",
                       cache = gargle::gargle_oauth_cache(),
                       use_oob = gargle::gargle_oob_default(),
                       token = NULL) { ... }

to the signature of credentials_gce():

credentials_gce <- function(scopes = "https://www.googleapis.com/auth/cloud-platform",
                            service_account = "default", ...) { ... }

If someone is not using the default service account, they need to specify service_account, but drive_auth() doesn't allow for that. One possible change is for drive_auth()-like functions to gain ... (probably right after email) and pass that along to token_fetch().

Or a different approach is for credentials_gce() to look at ... and, if email is present, use that as service_account.

I haven't thought deeply on this, but wanted to record the thought.

jennybc commented 1 year ago

Another argument for adding ... to PKG_auth()-like functions: there are already other arguments besides service_account that one might want to pass, such as sub. Will there be a slow trickle of such things and we'll be glad to have ...?

jennybc commented 1 year ago

Just to document if someone else is reading this, the current workaround for any situation like this is to call the credential fetcher directly with all necessary args and pass that token to PKG_auth(token =). So there's already a way to do this. This is about making it easier for a wrapper package user who probably doesn't want to know much about gargle.