cpfaff / rBExIS

Exchange data and metadata between R and BExIS II
3 stars 4 forks source link

Authenticate User #8

Open cpfaff opened 8 years ago

cpfaff commented 8 years ago

When users download and upload data they need to authenticate. This can be done with curl package directly:

# Set your browsing links
loginurl = "http://api.my.url/login"
dataurl  = "http://api.my.url/data"

#Set user account data and agent
pars=list(
username="xxx"
password="yyy"
)

agent="Mozilla/5.0" #or whatever
#Set RCurl pars
curl = getCurlHandle()
# curlSetOpt(cookiejar="", useragent = agent, followlocation = TRUE, curl=curl)
curlSetOpt(cookiejar="cookie.txt", useragent = agent, followlocation = TRUE, curl=curl)
# Login
html = postForm(loginurl, .params = pars, curl=curl)
#Go wherever you want
html = getURL(dataurl, curl=curl)

another option would be to use the httr package

require(httr)
GET("authenticationurl", authenticate(user="username", password="pass"))
store = GET("urlToData")

It takes care of the cookies and persists them over the calls to the same url. I think we should go the second way.