Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export(gargle_map_cli)
export(gargle_oauth_cache)
export(gargle_oauth_client)
export(gargle_oauth_client_from_json)
export(gargle_oauth_client_type)
export(gargle_oauth_email)
export(gargle_oauth_sitrep)
export(gargle_oob_default)
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ Changes of note:

gargle is better able to detect when it's running on Posit Workbench or RStudio Server, e.g., in a subprocess.

`gargle_oauth_client_type()` is a new function that returns either "installed"
or "web".
It returns the value of the new global option by the same name (`"gargle_oauth_client_type"`), if defined.
If the option is not defined, returns "web" on RStudio Server, Posit Workbench, or Posit Cloud, and "installed" otherwise.
In the context of out-of-band (OOB) auth, an "installed" client type leads to the conventional OOB flow (only available for GCP projects in testing mode) and a "web" client leads to the new pseudo-OOB flow.

# gargle 1.3.0

## (Partial) deprecation out-of-band (OOB) auth flow
Expand Down
21 changes: 21 additions & 0 deletions R/gargle-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,24 @@ gargle_oob_default <- function() {
gargle_oauth_cache <- function() {
getOption("gargle_oauth_cache", default = NA)
}

#' @rdname gargle_options
#' @export
#' @section `gargle_oauth_client_type`:
#' `gargle_oauth_client_type()` returns the option named
#' "gargle_oauth_client_type", if defined. If defined, the option must be either
#' "installed" or "web". If the option is not defined, the function returns:
#' * "web" on RStudio Server, Posit Workbench, or Posit Cloud
#' * "installed" otherwise
#' Primarily intended to help infer the most suitable OAuth client when a user
#' is relying on a built-in client, such as the tidyverse client used by
#' packages like bigrquery, googledrive, and googlesheets4.
gargle_oauth_client_type <- function() {
opt <- getOption("gargle_oauth_client_type")
if (is.null(opt)) {
if(is_rstudio_server()) "web" else "installed"
} else {
check_string(opt)
arg_match(opt, values = c("installed", "web"))
}
}
4 changes: 2 additions & 2 deletions R/gargle_oauth_client.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ list_redact <- function(x, names, case_sensitive = TRUE) {
#' }
gargle_client <- function(type = NULL) {
if (is.null(type) || is.na(type)) {
type <- if(is_rstudio_server()) "web" else "installed"
type <- gargle_oauth_client_type()
}
check_string(type)
type <- arg_match(type, values = c("installed", "web"))
Expand All @@ -218,7 +218,7 @@ tidyverse_client <- function(type = NULL) {
check_permitted_package(parent.frame())

if (is.null(type) || is.na(type)) {
type <- if(is_rstudio_server()) "web" else "installed"
type <- gargle_oauth_client_type()
}
check_string(type)
type <- arg_match(type, values = c("installed", "web"))
Expand Down
17 changes: 17 additions & 0 deletions man/gargle_options.Rd

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

8 changes: 8 additions & 0 deletions tests/testthat/test-assets.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ test_that("default options", {
withr::local_options(list(
gargle_oauth_cache = NULL,
gargle_oob_default = NULL, httr_oob_default = NULL,
gargle_oauth_client_type = NULL,
gargle_oauth_email = NULL,
gargle_verbosity = NULL,
gargle_quiet = NULL
))
expect_equal(gargle_oauth_cache(), NA)
if (is_rstudio_server()) {
expect_true(gargle_oob_default())
expect_equal(gargle_oauth_client_type(), "web")
} else {
expect_false(gargle_oob_default())
expect_equal(gargle_oauth_client_type(), "installed")
}
expect_null(gargle_oauth_email())
expect_equal(gargle_verbosity(), "info")
Expand All @@ -32,6 +35,11 @@ test_that("gargle_oob_default() consults httr's option", {
expect_true(gargle_oob_default())
})

test_that("gargle_oauth_client_type() consults the option", {
withr::local_options(list(gargle_oauth_client_type = "web"))
expect_equal(gargle_oauth_client_type(), "web")
})

test_that("gargle API key", {
key <- gargle_api_key()
expect_true(is_string(key))
Expand Down