From 7e17015f3e16a50c5c6af84e277210dd5a769f84 Mon Sep 17 00:00:00 2001 From: Daniel Russ Date: Fri, 17 Mar 2023 15:26:23 -0400 Subject: [PATCH] allow developer token, update documentation changed order of developer_token in box_auth --- DESCRIPTION | 2 +- R/boxr_auth.R | 27 +++++++++++++++++---------- man/box_auth.Rd | 8 +++++++- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ae0d4e7c..70714719 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -67,7 +67,7 @@ Suggests: usethis, covr VignetteBuilder: knitr -RoxygenNote: 7.1.2 +RoxygenNote: 7.2.3 Encoding: UTF-8 Roxygen: list(markdown = TRUE) RdMacros: lifecycle diff --git a/R/boxr_auth.R b/R/boxr_auth.R index eeddbfb6..04ac9749 100644 --- a/R/boxr_auth.R +++ b/R/boxr_auth.R @@ -55,6 +55,8 @@ #' @param interactive `logical`, indicates that the authorization process #' will be interactive (requiring user input to the R console, and/or a #' visit to [box.com](https://developer.box.com/docs)). +#' @param developer_token `character`, Optional developer token used for +#' authentication. #' @param write.Renv **deprecated**. #' @param ... Other arguments passed to [httr::oauth2.0_token()]. #' @@ -71,7 +73,7 @@ #' box_auth <- function(client_id = NULL, client_secret = NULL, interactive = TRUE, cache = "~/.boxr-oauth", - write.Renv, ...) { + write.Renv, developer_token= NULL, ...) { # deprecate write.Renv if (!missing(write.Renv)) { @@ -161,16 +163,21 @@ box_auth <- function(client_id = NULL, client_secret = NULL, base_url = "https://app.box.com/api/oauth2" ) - insistent_token <- purrr::insistently(httr::oauth2.0_token, quiet = FALSE) + if (is.null(developer_token)){ + insistent_token <- purrr::insistently(httr::oauth2.0_token, quiet = FALSE) - box_token <- - insistent_token( - box_endpoint, - box_app, - use_oob = getOption("httr_oob_default"), - cache = cache, - ... - ) + box_token <- + insistent_token( + box_endpoint, + box_app, + use_oob = getOption("httr_oob_default"), + cache = cache, + ... + ) + } else { + credentials <- list(access_token=developer_token,token_type="bearer") + box_token <- httr::oauth2.0_token(box_endpoint, box_app, credentials = credentials) + } if (!exists("box_token")) { stop("Login at box.com failed; unable to connect to API.") diff --git a/man/box_auth.Rd b/man/box_auth.Rd index 0eb53de8..d3e43fba 100644 --- a/man/box_auth.Rd +++ b/man/box_auth.Rd @@ -10,6 +10,7 @@ box_auth( interactive = TRUE, cache = "~/.boxr-oauth", write.Renv, + developer_token = NULL, ... ) } @@ -31,6 +32,9 @@ A string means use the specified path as the cache file.} \item{write.Renv}{\strong{deprecated}.} +\item{developer_token}{\code{character}, Optional developer token used for +authentication.} + \item{...}{Other arguments passed to \code{\link[httr:oauth2.0_token]{httr::oauth2.0_token()}}.} } \value{ @@ -68,7 +72,9 @@ This function has some side effects which make subsequent calls to \item a browser window may be opened at \href{https://developer.box.com/docs}{box.com}, for you to authorize to your Box app. \item a token file is written, according to the value of \code{cache}. The default -behaviour is to write this file to \verb{~/.boxr-oauth}. +behavior is to write this file to \verb{~/.boxr-oauth}. +For all platforms, \code{~} resolves to the home directory, i.e. path is +resolved using \code{\link[fs:path_expand]{fs::path_expand()}} rather than \code{\link[fs:path_expand]{fs::path_expand_r()}}. \item some global \code{\link[=options]{options()}} are set for your session to manage the token. \item environment variables \code{BOX_USER_ID}, \code{BOX_CLIENT_ID}, and \code{BOX_CLIENT_SECRET} are set.