Skip to content

Commit

Permalink
Truly deprecate old auth functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed May 2, 2023
1 parent 61b2985 commit c20f12b
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 128 deletions.
7 changes: 5 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
will see deprecation warnings in more contexts.

The unexported helper `gmailr:::gm_convert_file(list.files(pattern = "[.]R$", recursive = TRUE))`
can be used to convert all R files in the current directory to the new names.
(#95)
can be used to convert all R files in the current directory to the new names
(#95).

* Legacy auth function `clear_token()`, `gmail_auth()`, and `use_secret_file()`
now throw an error.

* `gm_auth_configure()` accepts an OAuth client (or "app"), via the `app`
argument, as promised in the docs (#144).
Expand Down
88 changes: 25 additions & 63 deletions R/deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -334,84 +334,46 @@ get_deprecated_funs <- function() {

# old auth ----

get_token <- function() {
if (!exists("token", the)) {
gmail_auth()
}
the$token
}

#' Clear the current oauth token
#' Deprecated auth
#'
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' These functions are deprecated and no longer work.
#' @name gmailr-deprecated-auth
#' @keywords internal

#' @rdname gmailr-deprecated-auth
#' @export
clear_token <- function() {
.Deprecated("gm_deauth()", package = "gmailr")
unlink(".httr-oauth")
the$token <- NULL
lifecycle::deprecate_stop(
when = "2.0.0",
what = "clear_token()",
with = "gm_deauth()"
)
}

#' Setup oauth authentication for your gmail
#'
#' @param scope the authentication scope to use
#' @param id the client_id to use for authentication
#' @param secret the client secret to use for authentication
#' @param secret_file the secret json file downloaded from <https://console.cloud.google.com>
#' @seealso use_secret_file to set the default id and secret to a different
#' value than the default.
#' @rdname gmailr-deprecated-auth
#' @export
#' @keywords internal
#' @examples
#' \dontrun{
#' gmail_auth("compose")
#' }
gmail_auth <- function(scope = c("read_only", "modify", "compose", "full"),
id = the$id,
secret = the$secret,
secret_file = NULL) {
.Deprecated("gm_auth() or gm_token()", package = "gmailr")

if (!is.null(secret_file)) {
if (!(missing(id) && missing(secret))) {
stop("You should set either ", sQuote("secret_file"), " or ",
sQuote("id"), " and ", sQuote("secret"), ", not both",
call. = FALSE
)
}
use_secret_file(secret_file)

# Use new ID and secret
id <- the$id
secret <- the$secret
}
myapp <- oauth_app("google", id, secret)

scope_urls <- c(
read_only = "https://www.googleapis.com/auth/gmail.readonly",
modify = "https://www.googleapis.com/auth/gmail.modify",
compose = "https://www.googleapis.com/auth/gmail.compose",
full = "https://mail.google.com/"
lifecycle::deprecate_stop(
when = "2.0.0",
what = "gmail_auth()",
with = "gm_auth()"
)
scope <- scope_urls[match.arg(scope, several.ok = TRUE)]

the$token <- oauth2.0_token(oauth_endpoints("google"), myapp, scope = scope)
}

#' Use information from a secret file
#'
#' This function sets the default secret and client_id to those in the secret
#' file
#' @param filename the filename of the file
#' @keywords internal
#' @rdname gmailr-deprecated-auth
#' @export
use_secret_file <- function(filename) {
.Deprecated(msg = paste0(
"Use `gm_auth_configure()` to configure your own OAuth app. That will\n",
"dictate the app used when `gm_auth()` is called implicitly or explicitly to\n",
"obtain an OAuth2 token."
))
info <- jsonlite::fromJSON(readChar(filename, nchars = 1e5))
the$secret <- info$installed$client_secret
the$id <- info$installed$client_id
lifecycle::deprecate_stop(
when = "2.0.0",
what = "use_secret_file()",
with = "gm_auth_configure()"
)
}

# nocov end
12 changes: 0 additions & 12 deletions man/clear_token.Rd

This file was deleted.

35 changes: 0 additions & 35 deletions man/gmail_auth.Rd

This file was deleted.

26 changes: 26 additions & 0 deletions man/gmailr-deprecated-auth.Rd

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

16 changes: 0 additions & 16 deletions man/use_secret_file.Rd

This file was deleted.

0 comments on commit c20f12b

Please sign in to comment.