This R6 class manages API authentication credentials, including token storage, expiration checks, and token refreshing.
Public fields
access_tokenAccess token for API authentication.
refresh_tokenRefresh token for obtaining a new access token.
token_typeType of token, usually "Bearer".
access_expires_inTimestamp when the access token expires.
refresh_expires_inTimestamp when the refresh token expires.
roleUser role assigned by the API (e.g., "admin").
last_loginTimestamp of the last successful login.
hostAPI base URL. Initialize the API credentials.
Methods
Method new()
Usage
ApiCredentials$new(
access_token,
refresh_token,
token_type,
access_expires_in,
refresh_expires_in,
role,
last_login,
host
)Arguments
access_tokenAccess token string.
refresh_tokenRefresh token string.
token_typeToken type (default: "Bearer").
access_expires_inExpiration timestamp for access token.
refresh_expires_inExpiration timestamp for refresh token.
roleUser role (e.g., "admin").
last_loginTimestamp of the last login.
hostAPI base URL.
Examples
# Create an instance with API credentials
creds <- ApiCredentials$new(
access_token = "your_access_token",
refresh_token = "your_refresh_token",
token_type = "Bearer",
access_expires_in = "2025-02-26T11:16:04.020256331Z",
refresh_expires_in = "2025-02-27T11:01:04.020409021Z",
role = "admin",
last_login = "2025-02-26T11:00:30Z",
host = "https://medinfo.precisiondosing.de/api/v1"
)
# Check token validity
creds$access_token_valid()
#> [1] FALSE
# Refresh tokens
if (FALSE) { # \dontrun{
creds$refresh(
"new_access_token", "new_refresh_token",
"2025-03-01T12:00:00Z", "2025-03-02T12:00:00Z"
)
} # }