#' Retrieve a token from vahydro REST service. TBD: replace with object to store token and dn connection
#' @param base_url character deprecated to be replaced by global datasource
#' @param rest_uname username to authenticate (if omitted will prompt)
#' @param rest_pw password to authenticate (if omitted will prompt)
#' @return token character from VAHydro REST web service
#' @seealso NA
#' @export om_vahydro_token
#' @examples NA
om_vahydro_token <- function(base_url='http://deq2.bse.vt.edu/d.dh', rest_uname = NULL, rest_pw = NULL) {
if (is.null(rest_uname)) {
# readline does *not* wait for input when run inside a fn but getPass does
rest_uname <- getPass::getPass("REST User Name: ")
}
if (is.null(rest_pw)) {
rest_pw <- getPass::getPass("REST Password: ")
}
message(paste("reading from", base_url))
# do something
#Cross-site Request Forgery Protection (Token required for POST and PUT operations)
csrf_url <- paste(base_url,"restws/session/token/",sep="/");
#message(paste("REST AUTH INFO HAS BEEN SUPPLIED",sep=""))
#message(paste("RETRIEVING REST TOKEN",sep=""))
csrf <- httr::GET(url=csrf_url,httr::authenticate(rest_uname,rest_pw));
#message(csrf)
token <- httr::content(csrf);
if (length(token)==1){
#message("Login attempt successful")
#message(paste("token = ",token,sep=""))
} else {
message("Login attempt unsuccessful")
}
return(token)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.