Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add box_url param to relevant functions; update docs #241

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 15 additions & 5 deletions R/boxr_auth.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
#' the client id for the account to use.
#' @param client_secret `character`,
#' the client secret for the account to use.
#' @param box_url `character`,
#' the url to box. Defaults to https://app.box.com, but can be set to enterprise Box URLs
#' @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)).
Expand All @@ -70,6 +72,7 @@
#' @export
#'
box_auth <- function(client_id = NULL, client_secret = NULL,
box_url = NULL,
interactive = TRUE, cache = "~/.boxr-oauth",
write.Renv, ...) {

Expand All @@ -87,6 +90,7 @@ box_auth <- function(client_id = NULL, client_secret = NULL,
# read environment variables
client_id_env <- Sys.getenv("BOX_CLIENT_ID")
client_secret_env <- Sys.getenv("BOX_CLIENT_SECRET")
box_url_env <- Sys.getenv("BOX_URL")

# if no input, look to .Renviron for the id and secret
if (is_void(client_id) && !is_void(client_id_env)) {
Expand All @@ -98,6 +102,11 @@ box_auth <- function(client_id = NULL, client_secret = NULL,
message("Using `BOX_CLIENT_SECRET` from environment")
client_secret <- client_secret_env
}
if (is_void(box_url) && !is_void(box_url_env)){
box_url <- box_url_env
} else {
box_url <- "https://app.box.com/"
}

# UI for interactively entering ids and secrets
if (is_void(client_id) && interactive()) {
Expand Down Expand Up @@ -153,12 +162,12 @@ box_auth <- function(client_id = NULL, client_secret = NULL,
key = client_id,
secret = client_secret
)

box_url <- ifelse(endsWith("/", box_url), box_url, paste0(box_url, "/"))
box_endpoint <-
httr::oauth_endpoint(
authorize = "authorize",
access = "token",
base_url = "https://app.box.com/api/oauth2"
base_url = paste0(box_url, "api/oauth2")
)

insistent_token <- purrr::insistently(httr::oauth2.0_token, quiet = FALSE)
Expand All @@ -173,7 +182,7 @@ box_auth <- function(client_id = NULL, client_secret = NULL,
)

if (!exists("box_token")) {
stop("Login at box.com failed; unable to connect to API.")
stop(paste("Login at", box_url, "failed; unable to connect to API."))
}

# write to options
Expand All @@ -194,8 +203,8 @@ box_auth <- function(client_id = NULL, client_secret = NULL,
# Write the details to the Sys.env
app_details <-
stats::setNames(
list(client_id, client_secret),
c("BOX_CLIENT_ID", "BOX_CLIENT_SECRET")
list(client_id, client_secret, box_url),
c("BOX_CLIENT_ID", "BOX_CLIENT_SECRET", "BOX_URL")
)

do.call(Sys.setenv, app_details)
Expand All @@ -213,6 +222,7 @@ box_auth <- function(client_id = NULL, client_secret = NULL,
glue::glue(
"BOX_CLIENT_ID={client_id}",
"BOX_CLIENT_SECRET={client_secret}",
"BOX_URL={box_url}",
.sep = "\n"
)
)
Expand Down
5 changes: 3 additions & 2 deletions R/boxr_misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ boxDirCreate <- function(dir_name, parent_dir_id = box_getwd()) {
#'
#' @param dir_id `numeric` or `character`, folder ID at Box.
#' @param file_id `numeric` or `character`, file ID at Box.
#' @param box_url `character`, url for box defaulting to https://app.box.com/;
#'
#' @return `r string_side_effects()`
#'
Expand All @@ -298,7 +299,7 @@ boxDirCreate <- function(dir_name, parent_dir_id = box_getwd()) {
#'
#' @export
#'
box_browse <- function(dir_id = NULL, file_id = NULL) {
box_browse <- function(dir_id = NULL, file_id = NULL, box_url="https://app.box.com") {
item <- collab_item_helper(dir_id, file_id)
utils::browseURL(glue::glue("https://app.box.com/{item$type}/{item$id}"))
utils::browseURL(glue::glue("{box_url}/{item$type}/{item$id}"))
}
9 changes: 9 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ box_auth()

If you don't have access to `client_id` and `client_secret`, you should read the [authentication article](`r url("articles/boxr-apps.html")`) to determine your next steps. In most cases, this next step will be to create an [interactive Box-app](`r url("articles/boxr-app-interactive.html")`)

### Authentication for Enterprise Box
To use `boxr` with enterprise accounts, the `box_url` parameter must be set:

```r
box_auth(client_id = "your_client_id", client_secret = "your_client_secret", box_url = "https://wayne-enterprises.ent.box.com")
```
You can also set the `BOX_URL` environment variable to your URL.


### Basic operations

- [Accessing Box files](`r url("articles/boxr.html#files")`): `box_ul()`, `box_dl()`, `box_version_history()`.
Expand Down
82 changes: 46 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ easier for you to integrate your Box account into your R workflow.

### Bug fixes

- Harmonizes the default location for tokens; `~` resolves to the home
directory for all platforms. A patch is applied offering to move
tokens from “old” locations. This bug appeared on Windows only.
- Harmonizes the default location for tokens; `~` resolves to the home
directory for all platforms. A patch is applied offering to move
tokens from “old” locations. This bug appeared on Windows only.

All changes are detailed in the
[NEWS](https://r-box.github.io/boxr/news/).
Expand All @@ -52,8 +52,8 @@ The package-documentation website is created and maintained using
[pkgdown](https://pkgdown.r-lib.org). The documentation website consists
of:

- a [CRAN-version site](https://r-box.github.io/boxr/).
- a [development-version site](https://r-box.github.io/boxr/dev/).
- a [CRAN-version site](https://r-box.github.io/boxr/).
- a [development-version site](https://r-box.github.io/boxr/dev/).

## Usage

Expand Down Expand Up @@ -86,46 +86,56 @@ determine your next steps. In most cases, this next step will be to
create an [interactive
Box-app](https://r-box.github.io/boxr/articles/boxr-app-interactive.html)

### Authentication for Enterprise Box

To use `boxr` with enterprise accounts, the `box_url` parameter must be
set:

``` r
box_auth(client_id = "your_client_id", client_secret = "your_client_secret", box_url = "https://wayne-enterprises.ent.box.com")
```

You can also set the `BOX_URL` environment variable to your URL.

### Basic operations

- [Accessing Box
files](https://r-box.github.io/boxr/articles/boxr.html#files):
`box_ul()`, `box_dl()`, `box_version_history()`.
- [Accessing Box
directories](https://r-box.github.io/boxr/articles/boxr.html#directories):
`box_setwd()`, `box_getwd()`, `box_dir_create()`, `box_ls()`,
`box_search()`.
- [Directory-wide
operations](https://r-box.github.io/boxr/articles/boxr.html#directory-wide-operations):
`box_push()`, `box_fetch()`.
- [Accessing Box
files](https://r-box.github.io/boxr/articles/boxr.html#files):
`box_ul()`, `box_dl()`, `box_version_history()`.
- [Accessing Box
directories](https://r-box.github.io/boxr/articles/boxr.html#directories):
`box_setwd()`, `box_getwd()`, `box_dir_create()`, `box_ls()`,
`box_search()`.
- [Directory-wide
operations](https://r-box.github.io/boxr/articles/boxr.html#directory-wide-operations):
`box_push()`, `box_fetch()`.

### Advanced operations

- [Interactng with Box
files](https://r-box.github.io/boxr/articles/boxr.html#box-file-interaction):
`box_collab_create()`, `box_comment_create()`,
`box_add_description()`.
- [Using Box
trash](https://r-box.github.io/boxr/articles/boxr.html#using-box-trash):
`box_delete_file()`, `box_delete_folder()`, `box_restore_file()`,
`box_restore_folder()`.
- [Interacting with your R
session](https://r-box.github.io/boxr/articles/boxr.html#interacting-with-your-r-session):
`box_read()`, `box_write()`, `box_read_rds()`, `box_save_rds()`,
`box_save()`, `box_load()`, `box_browse()`.
- [Interactng with Box
files](https://r-box.github.io/boxr/articles/boxr.html#box-file-interaction):
`box_collab_create()`, `box_comment_create()`,
`box_add_description()`.
- [Using Box
trash](https://r-box.github.io/boxr/articles/boxr.html#using-box-trash):
`box_delete_file()`, `box_delete_folder()`, `box_restore_file()`,
`box_restore_folder()`.
- [Interacting with your R
session](https://r-box.github.io/boxr/articles/boxr.html#interacting-with-your-r-session):
`box_read()`, `box_write()`, `box_read_rds()`, `box_save_rds()`,
`box_save()`, `box_load()`, `box_browse()`.

## Alternatives

Other ways to interact with a Box account include:

- The [Box desktop apps](https://www.box.com/resources/downloads).
- The *other* boxr, [written in
Ruby](https://github.com/cburnette/boxr). Its motivations are rather
different, and it covers 100% of the box.com API (e.g account
administration, etc.).
- Box themselves provide a [wide range of
SDKs](https://github.com/box), including [one for
Python](https://github.com/box/box-python-sdk).
- The [Box desktop apps](https://www.box.com/resources/downloads).
- The *other* boxr, [written in
Ruby](https://github.com/cburnette/boxr). Its motivations are rather
different, and it covers 100% of the box.com API (e.g account
administration, etc.).
- Box themselves provide a [wide range of SDKs](https://github.com/box),
including [one for Python](https://github.com/box/box-python-sdk).

## Contributing

Expand All @@ -139,7 +149,7 @@ Conduct](https://r-box.github.io/boxr/CONDUCT.html).

The MIT License (MIT)

Copyright (c) 2015-2022 boxr contributors
Copyright (c) 2015-2023 boxr contributors

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
Expand Down
8 changes: 7 additions & 1 deletion man/box_auth.Rd

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

4 changes: 3 additions & 1 deletion man/box_browse.Rd

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