Authentication

This vignette explains how to authenticate to the WAStD API.

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:

  • the API URL, and
  • an access token or a username / password.

There are three ways to supply the required settings to wastdr::get_wastd().

Best practice: .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.

Per session

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 settings>
#>   WAStD URL:     https://wastd.dbca.wa.gov.au 
#>   API URL:       https://wastd.dbca.wa.gov.au/api/1/ 
#>   API Token:     see wastdr::get_wastdr_api_token()
#>   API Username:  wastd_username 
#>   API Password:  see wastdr::get_wastdr_api_pw()
#>   Verbose:       FALSE

wastdr_setup defaults api_url to the currently only existing API url.

Per function call

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.