Sometimes when using connectapi
, customizing HTTP
requests is desirable. For instance, some common use cases are:
This is possible with connectapi
thanks to the
underlying library in use, httr
.
When you initialize a connectapi
API client, you
implicitly create a httr
HTTP client. The httr
package allows you to configure your HTTP requests globally using
set_config()
or in a scoped variant
with_config
. We will walk through a few examples below.
library(httr)
library(connectapi)
<- connect()
client
# notice that TLS verification fails
get_users(client)
# use a custom Certificate Authority to verify SSL/TLS requests
::set_config(httr::config(cainfo = "/path/to/my.pem"))
httr
# now it should succeed!
get_users(client)
Sometimes when first setting up a server, it is common to use self-signed certificates. This is generally bad for reliable communication and security (as there is no reason for any computer to trust this server as a “self-declared” trustworthy actor).
However, it can be useful while the organization’s Certificate Authority (CA) is in the process of issuing a valid certificate, or while a certificate is procured from a public CA.
# disabling certificate trust (can allow man-in-the-middle attacks, etc.)
::set_config(httr::config(ssl_verifypeer = 0))
httr
# should work
get_users(client)
Suffice it to say that effectively using Kerberos for HTTP is a bit
of an advanced topic. However, it is possible with
httr
.
It is worth noting that today, this interferes with API key authentication, which we are hoping to improve in a future release of RStudio Connect.
# disables authentication header that is included by default
$using_auth = FALSE
client
# use Kerberos authentication mechanism (requires local credential cache)
$httr_config(httr::authenticate(":", "", type="gssnegotiate")) client