drive_auth | R Documentation |
Authorize googledrive to view and manage your Drive files. This function is a
wrapper around gargle::token_fetch()
.
By default, you are directed to a web browser, asked to sign in to your Google account, and to grant googledrive permission to operate on your behalf with Google Drive. By default, with your permission, these user credentials are cached in a folder below your home directory, from where they can be automatically refreshed, as necessary. Storage at the user level means the same token can be used across multiple projects and tokens are less likely to be synced to the cloud by accident.
drive_auth(
email = gargle::gargle_oauth_email(),
path = NULL,
subject = NULL,
scopes = "drive",
cache = gargle::gargle_oauth_cache(),
use_oob = gargle::gargle_oob_default(),
token = NULL
)
email |
Optional. If specified,
Defaults to the option named |
path |
JSON identifying the service account, in one of the forms
supported for the |
subject |
An optional subject claim. Specify this if you wish to use the
service account represented by |
scopes |
One or more API scopes. Each scope can be specified in full or,
for Drive API-specific scopes, in an abbreviated form that is recognized by
See https://developers.google.com/drive/api/guides/api-specific-auth for details on the permissions for each scope. |
cache |
Specifies the OAuth token cache. Defaults to the option named
|
use_oob |
Whether to use out-of-band authentication (or, perhaps, a
variant implemented by gargle and known as "pseudo-OOB") when first
acquiring the token. Defaults to the value returned by
If the OAuth client is provided implicitly by a wrapper package, its type
probably defaults to the value returned by
|
token |
A token with class Token2.0 or an object of
httr's class |
Most users, most of the time, do not need to call drive_auth()
explicitly – it is triggered by the first action that requires
authorization. Even when called, the default arguments often suffice.
However, when necessary, drive_auth()
allows the user to explicitly:
Declare which Google identity to use, via an email
specification.
Use a service account token or workload identity federation via
path
.
Bring your own token
.
Customize scopes
.
Use a non-default cache
folder or turn caching off.
Explicitly request out-of-bound (OOB) auth via use_oob
.
If you are interacting with R within a browser (applies to RStudio
Server, Posit Workbench, Posit Cloud, and Google Colaboratory), you need
OOB auth or the pseudo-OOB variant. If this does not happen
automatically, you can request it explicitly with use_oob = TRUE
or,
more persistently, by setting an option via
options(gargle_oob_default = TRUE)
.
The choice between conventional OOB or pseudo-OOB auth is determined
by the type of OAuth client. If the client is of the "installed" type,
use_oob = TRUE
results in conventional OOB auth. If the client is of
the "web" type, use_oob = TRUE
results in pseudo-OOB auth. Packages
that provide a built-in OAuth client can usually detect which type of
client to use. But if you need to set this explicitly, use the
"gargle_oauth_client_type"
option:
options(gargle_oauth_client_type = "web") # pseudo-OOB # or, alternatively options(gargle_oauth_client_type = "installed") # conventional OOB
For details on the many ways to find a token, see
gargle::token_fetch()
. For deeper control over auth, use
drive_auth_configure()
to bring your own OAuth client or API key.
To learn more about gargle options, see gargle::gargle_options.
Other auth functions:
drive_auth_configure()
,
drive_deauth()
,
drive_scopes()
# load/refresh existing credentials, if available
# otherwise, go to browser for authentication and authorization
drive_auth()
# see user associated with current token
drive_user()
# force use of a token associated with a specific email
drive_auth(email = "jenny@example.com")
drive_user()
# force the OAuth web dance
drive_auth(email = NA)
# use a 'read only' scope, so it's impossible to edit or delete files
drive_auth(scopes = "drive.readonly")
# use a service account token
drive_auth(path = "foofy-83ee9e7c9c48.json")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.