Read a token and other credentials from a (non-REDCap) database or file.

Share:

Description

These functions are not essential to calling the REDCap API, but instead are functions that help manage tokens securely.

Usage

1
2
3
4
5
6
7
retrieve_credential_local(
  path_credential, project_id, check_url=TRUE, 
  check_username=FALSE, check_token_pattern=TRUE
)
retrieve_credential_mssql(
  project_id, instance, dsn, channel=NULL
)

Arguments

path_credential

The file path to the CSV containing the credentials. Required.

project_id

The ID assigned to the project withing REDCap. This allows the user to store tokens to multiple REDCap projects in one file. Required

check_url

A logical value indicates if the url in the credential file should be checked to have approximately the correct form. Defaults to TRUE.

check_username

A logical value indicates if the username in the credential file should be checked against the username returned by R. Defaults to FALSE.

check_token_pattern

A logical value indicates if the token in the credential file is a 32-character hexadecimal string. Defaults to FALSE.

instance

The casual name associated with the REDCap instance on campus. This allows one credential system to accommodate multiple instances on campus. Required

dsn

A DSN on the local machine that points to the desired MSSQL database. Required.

channel

An optional connection handle as returned by RODBC::odbcConnect. See Details below. Optional.

Details

If the database elements are created with the script provided in package's ‘Security Database’ vignette, the default values will work.

Value

A list of the following elements

  1. redcap_uri: The URI of the REDCap Server.

  2. username: Username.

  3. project_id: The ID assigned to the project withing REDCap.

  4. token: The token to pass to the REDCap server

  5. comment: An optional string.

Note

Although we strongly encourage storing all the tokens on a central server (e.g., see the retrieve_credential_mssql() function and the "SecurityDatabase" vignette), there are times when this approach is not feasible and the token must be stored locally. Please contact us if your institution is using something other than SQL Server, and would like help adapting this approach to your infrastructure.

Author(s)

Will Beasley

Examples

1
2
3
4
5
library(REDCapR) #Load the package into the current R session.
# ---- Local File Example ----------------------------
path <- system.file("misc/example.credentials", package="REDCapR")
(p1  <- retrieve_credential_local(path, 153L))
(p2  <- retrieve_credential_local(path, 212L))