Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d6521ff
added ability to pass url query parameters to initial authorization page
cosmomeese Jan 22, 2018
05e38c3
fixed syntax error for previous commit
cosmomeese Jan 22, 2018
df9923b
added ability to pass query params to authorization page
cosmomeese Jan 23, 2018
935f560
changed default auth_page_query_params from NULL to list() to fix unu…
cosmomeese Jan 23, 2018
79fd5fd
fixed error resulting from moving auth_page_query_params to end of li…
cosmomeese Jan 23, 2018
f883c30
removed unnecessary (& incorrect) reference to auth_page_query_params…
cosmomeese Jan 23, 2018
a3478e3
updated documentation + fixed auth_page_query_params so they all defa…
cosmomeese Jan 26, 2018
1d85300
added some unit tests
cosmomeese Jan 26, 2018
d19e1a2
updated code to match tidyverse style guide (using 'styler' package)
cosmomeese Nov 22, 2018
da325ec
Merge branch 'master' into master
cosmomeese Nov 22, 2018
b66806b
reversed unnecessary style changes
cosmomeese Nov 22, 2018
2a55408
updated style (using styler package & manual changes where necessary)
cosmomeese Nov 22, 2018
1d45bf7
Merge commit '5345aaf04486a507f5fcfe028225f4f4d7c8afa6'
cosmomeese Nov 22, 2018
81b6017
Merge branch 'master' into experiment
cosmomeese Nov 22, 2018
07dd312
re-styled (using 'styler') ugly code missed on first pass
cosmomeese Nov 22, 2018
9e2d5d9
re-styled (using 'styler') ugly code missed on second pass
cosmomeese Nov 22, 2018
f56170c
manual re-style for complicated code block
cosmomeese Nov 22, 2018
1acdfac
force travis CI rebuild
cosmomeese Nov 22, 2018
b10ca89
manual re-re-style for complicated code block
cosmomeese Nov 22, 2018
a330073
improved code smell
cosmomeese Nov 26, 2018
d92d7e9
dropped bracket
cosmomeese Nov 26, 2018
54b922b
updated man pages & made sure oauth2.0_authorize_url can still receiv…
cosmomeese Nov 26, 2018
89a1c42
corrected test
cosmomeese Nov 26, 2018
9799af1
updated man pages
cosmomeese Nov 26, 2018
bfc3274
clarify code
cosmomeese Nov 26, 2018
54008e6
added default param for query_extra
cosmomeese Nov 26, 2018
6c70919
updated manpages
cosmomeese Nov 26, 2018
b12b426
replaced oauth2.0_authorize_url test for empty input & updated style
cosmomeese Nov 27, 2018
4ce00ab
updated news
cosmomeese Nov 28, 2018
5971fda
updated news (again)
cosmomeese Nov 28, 2018
f51cfa9
Merge branch 'master' into master
cosmomeese Dec 3, 2018
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 @@ -116,3 +116,4 @@ export(write_function)
export(write_memory)
export(write_stream)
importFrom(R6,R6Class)
importFrom(utils,modifyList)
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

* The default value of `failure` argument in `parse_http_date()` is set to `structure(NA_real_, class = "Date")` so that the reponse with a "failure" date can be printed out correctly. (@shrektan, #544)

* `oauth2.0_token` & `init_oauth2.0` (through the new `query_authorize_extra` parameter) as well as `oauth2.0_authorize_url()` (through new `query_extra` parameter) gain the ability to append extra user-specified URL query parameters (as named `list()`) to the oauth2.0 authorization URL used to initially request an oauth2.0 token from the authentication server; this is useful for some APIs (e.g. Fitbit) (@cosmomeese, #503).

# httr 1.3.1

* Re-enable on-disk caching (accidentally disabled in #457) (#475)
Expand Down
31 changes: 25 additions & 6 deletions R/oauth-init.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ init_oauth1.0 <- function(endpoint, app, permission = NULL,
#' @param client_credentials Default to \code{FALSE}. Set to \code{TRUE} to use
#' \emph{Client Credentials Grant} instead of \emph{Authorization
#' Code Grant}. See \url{https://tools.ietf.org/html/rfc6749#section-4.4}.
#' @param query_authorize_extra Default to \code{list()}. Set to named list
#' holding query parameters to append to initial auth page query. Useful for
#' some APIs.
#' @export
#' @keywords internal
init_oauth2.0 <- function(endpoint, app, scope = NULL,
Expand All @@ -79,7 +82,8 @@ init_oauth2.0 <- function(endpoint, app, scope = NULL,
is_interactive = interactive(),
use_basic_auth = FALSE,
config_init = list(),
client_credentials = FALSE
client_credentials = FALSE,
query_authorize_extra = list()
) {

scope <- check_scope(scope)
Expand All @@ -102,7 +106,8 @@ init_oauth2.0 <- function(endpoint, app, scope = NULL,
app,
scope = scope,
redirect_uri = redirect_uri,
state = state
state = state,
query_extra = query_authorize_extra
)
code <- oauth_authorize(authorize_url, use_oob)
}
Expand All @@ -121,18 +126,32 @@ init_oauth2.0 <- function(endpoint, app, scope = NULL,
}

#' @export
#' @importFrom utils modifyList
#' @rdname init_oauth2.0
#' @param query_extra See \code{query_authorize_extra}
oauth2.0_authorize_url <- function(endpoint, app, scope,
redirect_uri = app$redirect_uri,
state = nonce()
state = nonce(),
query_extra = list()
) {
modify_url(endpoint$authorize, query = compact(list(
#TODO might need to put some params before and some after...

query_extra <- query_extra %||% list() # i.e. make list if query_extra is null

default_query <- list(
client_id = app$key,
scope = scope,
redirect_uri = redirect_uri,
response_type = "code",
state = state)
))
state = state
)

query <- compact(modifyList(default_query, query_extra))

modify_url(
endpoint$authorize,
query = query
)
}

#' @export
Expand Down
10 changes: 7 additions & 3 deletions R/oauth-token.r
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ oauth2.0_token <- function(endpoint, app, scope = NULL, user_params = NULL,
cache = getOption("httr_oauth_cache"),
config_init = list(),
client_credentials = FALSE,
credentials = NULL
credentials = NULL,
query_authorize_extra = list()
) {
params <- list(
scope = scope,
Expand All @@ -229,7 +230,8 @@ oauth2.0_token <- function(endpoint, app, scope = NULL, user_params = NULL,
as_header = as_header,
use_basic_auth = use_basic_auth,
config_init = config_init,
client_credentials = client_credentials
client_credentials = client_credentials,
query_authorize_extra = query_authorize_extra
)

Token2.0$new(
Expand All @@ -251,7 +253,9 @@ Token2.0 <- R6::R6Class("Token2.0", inherit = Token, list(
oob_value = self$params$oob_value,
use_basic_auth = self$params$use_basic_auth,
config_init = self$params$config_init,
client_credentials = self$params$client_credentials)
client_credentials = self$params$client_credentials,
query_authorize_extra = self$params$query_authorize_extra
)
},
can_refresh = function() {
!is.null(self$credentials$refresh_token)
Expand Down
17 changes: 12 additions & 5 deletions man/init_oauth2.0.Rd

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

7 changes: 6 additions & 1 deletion man/oauth2.0_token.Rd

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

39 changes: 39 additions & 0 deletions tests/testthat/test-oauth.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,45 @@ test_that("oauth_encode1 works", {
expect_equal(orig_string, restored_string)
})

test_that("oauth2.0 authorize url appends query params", {
app <- oauth_app("x", "y", "z")
scope <- NULL
query_extra <- list(
foo = "bar"
)
authURL <- oauth2.0_authorize_url(
endpoint = oauth_endpoints("google"),
app = app,
scope = scope,
query_extra = query_extra
)

url <- parse_url(authURL)
expect_equal(url$query$foo, "bar")
})

test_that("oauth2.0 authorize url handles empty query_extra input", {
# common constructor
authorize_url_extra_params <- function(extra_params)
{
app <- oauth_app("x", "y", "z")
scope <- NULL

url_with_empty_input <- oauth2.0_authorize_url(
endpoint = oauth_endpoints("google"),
app = app,
scope = scope,
state = "testing-nonce",
query_extra = extra_params
)
parse_url(url_with_empty_input)$query
}

# expect NA (i.e. no) error
expect_error(authorize_url_extra_params(list()), NA) # with empty list
expect_error(authorize_url_extra_params(NULL), NA) # with NULL list
})

# Parameter checking ------------------------------------------------------

test_that("scope must be character or NULL", {
Expand Down