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
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
^CRAN-RELEASE$
^revdep$
^CRAN-SUBMISSION$
^[\.]?air\.toml$
^\.vscode$
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["Posit.air-vscode"]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"[r]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "Posit.air-vscode"
}
}
25 changes: 14 additions & 11 deletions R/content-type.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
#'
#' # `types` can also specify multiple valid types
#' resp_check_content_type(resp, c("application/xml", "application/json"))
resp_check_content_type <- function(resp,
valid_types = NULL,
valid_suffix = NULL,
check_type = TRUE,
call = caller_env()) {

resp_check_content_type <- function(
resp,
valid_types = NULL,
valid_suffix = NULL,
check_type = TRUE,
call = caller_env()
) {
check_response(resp)
check_character(valid_types, allow_null = TRUE)
check_string(valid_suffix, allow_null = TRUE)
Expand Down Expand Up @@ -89,11 +90,13 @@ parse_content_type <- function(x) {
)
}

check_content_type <- function(content_type,
valid_types = NULL,
valid_suffix = NULL,
inform_check_type = FALSE,
call = caller_env()) {
check_content_type <- function(
content_type,
valid_types = NULL,
valid_suffix = NULL,
inform_check_type = FALSE,
call = caller_env()
) {
parsed <- parse_content_type(content_type)
base_type <- paste0(parsed$type, "/", parsed$subtype)

Expand Down
25 changes: 18 additions & 7 deletions R/curl.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ curl_translate <- function(cmd, simplify_headers = TRUE) {
cookies <- data$headers$`Cookie`
data$headers$`Cookie` <- NULL
if (!is.null(cookies)) {
steps <- add_curl_step(steps, "req_cookies_set", dots = cookies_parse(cookies))
steps <- add_curl_step(
steps,
"req_cookies_set",
dots = cookies_parse(cookies)
)
}

# Content type set with data
Expand Down Expand Up @@ -88,7 +92,12 @@ curl_translate <- function(cmd, simplify_headers = TRUE) {
if (data$verbose) {
perform_args$verbosity <- 1
}
steps <- add_curl_step(steps, "req_perform", main_args = perform_args, keep_if_empty = TRUE)
steps <- add_curl_step(
steps,
"req_perform",
main_args = perform_args,
keep_if_empty = TRUE
)
out <- paste0(steps, collapse = paste0(pipe(), "\n "))

if (clip) {
Expand Down Expand Up @@ -280,11 +289,13 @@ quote_name <- function(x) {
ifelse(is_syntactic(x), x, encodeString(x, quote = "`"))
}

add_curl_step <- function(steps,
f,
main_args = NULL,
dots = NULL,
keep_if_empty = FALSE) {
add_curl_step <- function(
steps,
f,
main_args = NULL,
dots = NULL,
keep_if_empty = FALSE
) {
args <- c(main_args, dots)

if (is_empty(args) && !keep_if_empty) {
Expand Down
12 changes: 7 additions & 5 deletions R/iterate-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@
#' max_reqs = Inf
#' )
#' }
iterate_with_offset <- function(param_name,
start = 1,
offset = 1,
resp_pages = NULL,
resp_complete = NULL) {
iterate_with_offset <- function(
param_name,
start = 1,
offset = 1,
resp_pages = NULL,
resp_complete = NULL
) {
check_string(param_name)
check_number_whole(start)
check_number_whole(offset, min = 1)
Expand Down
18 changes: 10 additions & 8 deletions R/jwt.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@
#' @examples
#' claim <- jwt_claim()
#' str(claim)
jwt_claim <- function(iss = NULL,
sub = NULL,
aud = NULL,
exp = unix_time() + 5L * 60L,
nbf = unix_time(),
iat = unix_time(),
jti = NULL,
...) {
jwt_claim <- function(
iss = NULL,
sub = NULL,
aud = NULL,
exp = unix_time() + 5L * 60L,
nbf = unix_time(),
iat = unix_time(),
jti = NULL,
...
) {
# https://datatracker.ietf.org/doc/html/rfc7519
jose::jwt_claim(
iss = iss,
Expand Down
60 changes: 37 additions & 23 deletions R/oauth-client.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@
#' @examples
#' oauth_client("myclient", "http://example.com/token_url", secret = "DONTLOOK")
oauth_client <- function(
id,
token_url,
secret = NULL,
key = NULL,
auth = c("body", "header", "jwt_sig"),
auth_params = list(),
name = hash(id)
) {

id,
token_url,
secret = NULL,
key = NULL,
auth = c("body", "header", "jwt_sig"),
auth_params = list(),
name = hash(id)
) {
check_string(id)
check_string(token_url)
check_string(secret, allow_null = TRUE)
Expand All @@ -66,7 +65,9 @@
cli::cli_abort("{.code auth = 'jwt_sig'} requires a {.arg key}.")
}
if (!has_name(auth_params, "claim")) {
cli::cli_abort("{.code auth = 'jwt_sig'} requires a claim specification in {.arg auth_params}.")
cli::cli_abort(
"{.code auth = 'jwt_sig'} requires a claim specification in {.arg auth_params}."
)
}
}

Expand Down Expand Up @@ -167,7 +168,8 @@
#' @export
#' @rdname oauth_client_req_auth
oauth_client_req_auth_header <- function(req, client) {
req_auth_basic(req,
req_auth_basic(
req,
username = client$id,
password = unobfuscate(client$secret)
)
Expand All @@ -176,7 +178,8 @@
#' @export
#' @rdname oauth_client_req_auth
oauth_client_req_auth_body <- function(req, client) {
req_body_form(req,
req_body_form(
req,
client_id = client$id,
client_secret = unobfuscate(client$secret) # might be NULL
)
Expand All @@ -185,24 +188,33 @@
#' @inheritParams jwt_claim
#' @export
#' @rdname oauth_client_req_auth
oauth_client_req_auth_jwt_sig <- function(req, client, claim, size = 256, header = list()) {
oauth_client_req_auth_jwt_sig <- function(
req,
client,
claim,
size = 256,
header = list()
) {
claim <- exec("jwt_claim", !!!claim)
jwt <- jwt_encode_sig(claim, key = client$key, size = size, header = header)

# https://datatracker.ietf.org/doc/html/rfc7523#section-2.2
req_body_form(req,
req_body_form(
req,

Check warning on line 203 in R/oauth-client.R

View check run for this annotation

Codecov / codecov/patch

R/oauth-client.R#L202-L203

Added lines #L202 - L203 were not covered by tests
client_assertion = jwt,
client_assertion_type = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
)
}

# Helpers -----------------------------------------------------------------

oauth_flow_check <- function(flow, client,
is_confidential = FALSE,
interactive = FALSE,
error_call = caller_env()) {

oauth_flow_check <- function(
flow,
client,
is_confidential = FALSE,
interactive = FALSE,
error_call = caller_env()
) {
if (!inherits(client, "httr2_oauth_client")) {
cli::cli_abort(
"{.arg client} must be an OAuth client created with {.fn oauth_client}.",
Expand All @@ -228,10 +240,12 @@
}
}

oauth_client_get_token <- function(client,
grant_type,
...,
error_call = caller_env()) {
oauth_client_get_token <- function(
client,
grant_type,
...,
error_call = caller_env()
) {
req <- request(client$token_url)
req <- req_body_form(req, grant_type = grant_type, ...)
req <- oauth_client_req_auth(req, client)
Expand Down
Loading
Loading