Skip to content

Commit c8d39aa

Browse files
authored
Less-zealous redirect_uri normalization (#666)
Closes #646
1 parent 4f00350 commit c8d39aa

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* `req_headers_redacted()` supports dynamic dots (#647)
88
* `resp_stream_sse()` now automatically retrieves the next event if the current event contains no data. The data is now returned as a single string (#650).
99
* `aws_v4_signature()` now works if url contains query parameters (@jeffreyzuber, #645).
10+
* `req_oauth_auth_code()` no longer adds trailing "/" characters to well-formed `redirect_uri` values (@jonthegeek, #646).
1011

1112
# httr2 1.1.0
1213

R/oauth-flow-auth-code.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ normalize_redirect_uri <- function(redirect_uri,
209209
port = deprecated(),
210210
error_call = caller_env()) {
211211

212-
parsed <- url_parse(redirect_uri)
212+
old <- parsed <- url_parse(redirect_uri)
213213

214214
if (lifecycle::is_present(host_name)) {
215215
lifecycle::deprecate_warn(
@@ -250,7 +250,7 @@ normalize_redirect_uri <- function(redirect_uri,
250250
}
251251

252252
list(
253-
uri = url_build(parsed),
253+
uri = if (identical(old, parsed)) redirect_uri else url_build(parsed),
254254
localhost = localhost,
255255
can_fetch_code = can_fetch_oauth_code(redirect_uri)
256256
)

tests/testthat/test-oauth-flow-auth-code.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ test_that("old args are deprecated", {
8888

8989
})
9090

91+
test_that("urls left as is if not changes needed", {
92+
# Allow tests to run when is_hosted_session() is TRUE.
93+
local_mocked_bindings(is_hosted_session = function() FALSE)
94+
95+
original_uri <- "http://localhost:8080"
96+
normalized_uri <- normalize_redirect_uri(original_uri)
97+
expect_equal(normalized_uri$uri, original_uri)
98+
})
99+
91100
# ouath_flow_auth_code_parse ----------------------------------------------
92101

93102
test_that("forwards oauth error", {
@@ -125,6 +134,7 @@ test_that("external auth code sources are detected correctly", {
125134

126135
test_that("auth codes can be retrieved from an external source", {
127136
skip_on_cran()
137+
local_mocked_bindings(sys_sleep = function(...) {})
128138

129139
req <- local_app_request(function(req, res) {
130140
# Error on first, and then respond on second

0 commit comments

Comments
 (0)