Skip to content

Commit

Permalink
Tweaks inspired by comparison to gs4_auth()
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Jun 2, 2023
1 parent c5a0739 commit 4ed4ead
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
23 changes: 13 additions & 10 deletions R/drive_auth.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## This file is the interface between googledrive and the
## auth functionality in gargle.
# This file is the interface between googledrive and the
# auth functionality in gargle.

# Initialization happens in .onLoad()
.auth <- NULL
Expand All @@ -23,8 +23,7 @@ gargle_lookup_table <- list(
#' @family auth functions
#' @export
#'
#' @examples
#' \dontrun{
#' @examplesIf rlang::is_interactive()
#' # load/refresh existing credentials, if available
#' # otherwise, go to browser for authentication and authorization
#' drive_auth()
Expand All @@ -46,7 +45,6 @@ gargle_lookup_table <- list(
#'
#' # use a service account token
#' drive_auth(path = "foofy-83ee9e7c9c48.json")
#' }
drive_auth <- function(email = gargle::gargle_oauth_email(),
path = NULL,
scopes = "https://www.googleapis.com/auth/drive",
Expand All @@ -56,6 +54,10 @@ drive_auth <- function(email = gargle::gargle_oauth_email(),
gargle::check_is_service_account(path, hint = "drive_auth_configure")
env_unbind(.googledrive, "root_folder")

# If `token` is not `NULL`, it's much better to error noisily now, before
# getting silently swallowed by `token_fetch()`.
force(token)

cred <- gargle::token_fetch(
scopes = scopes,
client = drive_oauth_client() %||% gargle::tidyverse_client(),
Expand Down Expand Up @@ -89,14 +91,15 @@ drive_auth <- function(email = gargle::gargle_oauth_email(),
#'
#' @family auth functions
#' @export
#' @examples
#' \dontrun{
#' @examplesIf rlang::is_interactive()
#' drive_deauth()
#' drive_user()
#' public_file <-
#' drive_get(as_id("1Hj-k7NpPSyeOR3R7j4KuWnru6kZaqqOAE8_db5gowIM"))
#'
#' # in a deauth'ed state, we can still get metadata on a world-readable file
#' public_file <- drive_example_remote("chicken.csv")
#' public_file
#' # we can still download it too
#' drive_download(public_file)
#' }
drive_deauth <- function() {
.auth$set_auth_active(FALSE)
.auth$clear_cred()
Expand Down
4 changes: 2 additions & 2 deletions man/drive_auth.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions man/drive_deauth.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4ed4ead

Please sign in to comment.