Following up on an earlier question by @arthur.t - https://community.rstudio.com/t/how-do-i-specity-authentication-type-in-httr2/140119 - I figured I should share what I worked out and see if anyone else has a more graceful solution.
tldr:
library(httr2)
response <- request("https://www.example.com") |>
req_options(httpauth = 8L) |>
req_options(userpwd = ":") |>
req_perform()
response
I need to do NTLM authentication while using httr2, which doesn't have the same range of easy authentication options as httr did. Turns out it's fairly easy but you need to get into the guts of curl to understand the numbers for options. You need to set the authentication option to CURLAUTH_NTLM
. I ended up using httr2::req_options(httpauth = 8L)
to pass this through to curl.
The option # for NTLM auth is 8 - you get that from finding CURLAUTH_NTLM
in the source code for curl.h. The value (((unsigned long)1)<<3)
calculates to 8 (1 x 2^3). Per curl::handle_setopt()
you need to set these kinds of options as a number, hence using 8L to get a long int.
I don't like the roundabout way I found this and I'm sure there's a better/easier way. Does anyone know it?