An APIAuthState object manages an authorization state for
authentication with SpeedGoat APIs. When using a SpeedGoat API
the user is identified by their email address and project ID.
One email can be associated with multiple projects.
Authentication is organized by realms. A realm is a named group of APIs
that share a single token authority. For example, the "counts" realm
includes the counts API and any satellite APIs (e.g., sightability) that
trust its tokens. Each realm stores its own token, refresh token, expiration,
and auth type independently.
Authentication mechanisms include:
OIDC for shiny applications
API key for automated processes by end users
OAuth for interactive sessions
Methods
Method new()
Create a new APIAuthState instance with default authentication endpoint
Returns
A new APIAuthState object
Print authentication state information
Returns
Invisibly returns self (chainable)
Method init_realm()
Initialize a realm with default (unauthenticated) state.
Usage
APIAuthState$init_realm(name, base_url)
Arguments
name
Realm name
base_url
Base API URL for the realm (e.g.,
"https://counts.spdgt.com/api")
Returns
Invisible self (chainable)
Method get_realm()
Get realm state
Usage
APIAuthState$get_realm(name)
Returns
Named list with realm state
Method get_realm_for_api()
Get the realm name for a given API
Usage
APIAuthState$get_realm_for_api(api_name)
Returns
Realm name string, or NULL
Method set_realm_token()
Store credentials for a realm.
Usage
APIAuthState$set_realm_token(
realm,
token,
refresh_token = NULL,
expiration = NULL,
auth_type = NULL
)
Arguments
realm
Realm name
token
Access token
refresh_token
Refresh token (optional)
expiration
Token expiration time (optional)
auth_type
Authentication type ("oauth", "oidc", or "api_key")
Returns
Invisible self (chainable)
Method get_realm_token()
Get token for a realm
Usage
APIAuthState$get_realm_token(realm)
Returns
Token string or NULL
Method get_realm_auth_type()
Get auth type for a realm
Usage
APIAuthState$get_realm_auth_type(realm)
Returns
Auth type string or NULL
Method get_realm_refresh_token()
Get refresh token for a realm
Usage
APIAuthState$get_realm_refresh_token(realm)
Returns
Refresh token string or NULL
Method get_realm_expiration()
Get expiration for a realm
Usage
APIAuthState$get_realm_expiration(realm)
Returns
Expiration POSIXct or NULL
Method is_realm_auth()
Check if a realm is authenticated
Usage
APIAuthState$is_realm_auth(realm)
Method clear_realm_cred()
Clear credentials for a single realm.
Usage
APIAuthState$clear_realm_cred(realm)
Returns
Invisible self (chainable)
Method forward_realm_token()
Forward a token to a specific realm.
Usage
APIAuthState$forward_realm_token(
realm,
token,
expires_in = 3600,
auth_type = "oidc"
)
Arguments
realm
Realm name
token
Token string
expires_in
Expiration time in seconds (default: 3600)
auth_type
Authentication type (default: "oidc")
Returns
Invisible self (chainable)
Method get_realm_url()
Derive auth URLs from a realm's base_url
Usage
APIAuthState$get_realm_url(realm, path)
Arguments
realm
Realm name
path
One of "me", "login", "refresh", "oidc", "logout"
Register an API endpoint and assign it to a realm.
Usage
APIAuthState$add_api(name, url, package = NULL, realm = NULL)
Arguments
name
API name
url
API URL
package
Package registering the API. If NULL, will be detected
from calling environment.
realm
Realm name. If NULL, creates a new realm named after the
API. If provided, joins the existing realm.
Returns
Invisible self (chainable)
Method get_api_url()
Get the registered URL for an API by name.
Usage
APIAuthState$get_api_url(name)
Method remove_api()
Remove an API registration.
Usage
APIAuthState$remove_api(name)
Returns
Invisible self (chainable)
Method get_user_agent()
Get the user agent string.
Usage
APIAuthState$get_user_agent()
Returns
User agent string
Method set_user_id()
Set user ID
Usage
APIAuthState$set_user_id(user_id)
Method get_user_id()
Get user ID
Usage
APIAuthState$get_user_id()
Method set_email()
Set user email.
Usage
APIAuthState$set_email(email)
Returns
Invisible self (chainable)
Method get_email()
Get user email
Method set_project_id()
Set project ID
Usage
APIAuthState$set_project_id(value)
Arguments
value
Project unique identifier
Method get_project_id()
Get project ID
Usage
APIAuthState$get_project_id()
Returns
Project unique identifier
Method set_project_abb()
Set project abbreviation
Usage
APIAuthState$set_project_abb(value)
Arguments
value
Project abbreviation string
Method get_project_abb()
Get project abbreviation
Usage
APIAuthState$get_project_abb()
Returns
Project abbreviation string or NULL
Method get_is_auth()
Get authentication status (any realm)
Usage
APIAuthState$get_is_auth()
Returns
Logical, TRUE if any realm is authenticated
Method clear_cred()
Clear all credentials (all realms and global identity).
Usage
APIAuthState$clear_cred()
Returns
Invisible self (chainable)
user_id User's unique identifier
email User's email address
project_id Project unique identifier
project_abb Project abbreviation
Get user agent string
User agent string
Method clone()
The objects of this class are cloneable with this method.
Usage
APIAuthState$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.