options(rmarkdown.html_vignette.check_title = FALSE) knitr::opts_chunk$set( collapse = T, eval = T, comment = "#>" )
This vignette explains how to authenticate to the WAStD API.
require(wastdr)
There are two audiences with two different authentication options.
The first audience, DBCA staff, has access to WAStD. On their profile page they will find their own API token.
The second audience, external collaborators, will be given a username and password.
Using these credentials, they can access the
WAStD API
both through their browser and from other software like wastdr
.
wastdr::get_wastd()
accesses the WAStD
API using:
There are three ways to supply the required settings to wastdr::get_wastd()
.
.Renviron
For a permanent setup, the environment variables can be set in the user's
.Renviron
.
DBCA staff visit their own profile on WAStD and add their API Token as advertised on their profile to their .Renviron
:
WASTDR_API_URL <- "https://tsc.dbca.wa.gov.au/api/1/" WASTDR_API_TOKEN <- "Token xxx"
Note that the API token contains the word Token
and a whitespace in addition
to the actual API token (an alphanumeric hash).
External collaborators add to their .Renviron
:
WASTDR_API_URL <- "https://tsc.dbca.wa.gov.au/api/1/" WASTDR_API_UN <- "XXX" WASTDR_API_PW <- "XXX"
In the long term, this last method is the most elegant and persistent way of
configuring wastdr
.
If api_*
settings are not provided, wastdr::get_wastd
defaults to
specifically named environment variables.
For convenience, wastdr_setup
sets these environment variables, while
wastdr_settings
retrieves the currently set values.
If these variables haven't been provided through e.g. .Renviron
, you may set
them on a per session basis:
wastdr::wastdr_setup(api_token = "Token XXX")
Alternatively you may use your username and password.
wastdr::wastdr_setup(api_un = "XXX", api_pw = "XXX")
Review the settings with:
wastdr::wastdr_settings()
wastdr_setup
defaults api_url
to the currently only existing API url.
Crendentials can be supplied directly to functions:
wastdr::wastd_GET("encounters", api_token = "Token XXX" ) wastdr::wastd_GET("encounters", api_un = "XXX", api_pw = "XXX" )
This method overrides any other settings, but leads to verbose code with confidential data (token or password) in plain text.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.