Basic authentication with the crul R package


Hi everyone,

Thanks for the really nice crul package. I would like to use it to create a R api package but I have an issue.
I tried to dig into the documentation with no success.

I want to know how to do basic http (or other methods) authentication like in Python requests or with R package httr.

Here are two examples of what I want to achieve with crul (let me know if it is right place such question or I should as it at SO).

import requests
from requests.auth import HTTPBasicAuth
requests.get("", auth = ('username', 'password'))

Or with the package R httr

GET(url = '', authenticate(user = 'username', password = 'password'))

Thanks again for the support

Thanks for your question @dickoa

We didn’t have anything to support that yet - though you could do it with curl options yourself, but that’s a bit tedious if you aren’t familiar with them.

Reinstall devtools::install_github("ropensci/crul") and see ?auth


res <- HttpClient$new(
  url = "",
  auth = auth(user = "user", pwd = "passwd")
x <- res$get()
1 Like

Thanks a lot @sckott, it works perfectly.
Thanks again for this package it’s really a nice addition to the web stack in R.


glad it works :smiley: