#' Get GLIS API token
#'
#' A helper function to fetch a token from the GLIS API. The token is
#' added to the GET request header. A new token is needed every 24 hours
#' (or when the existing token is cleared from the Global Environment).
#'
#' @return string
#' @export
get_token <- function() {
body <- get_credentials()
domain <- get_domain()
resp <- httr::POST(sprintf("%sapi-auth/token/", domain), body = body)
token <- httr::content(resp)
if (is.null(token$non_field_errors)) {
assign("token", token, envir = .GlobalEnv)
message("You have been successfully authenticated on the GLIS server.")
} else {
assign("token", NULL, envir = .GlobalEnv)
warning(token$non_field_errors)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.