| Title: | Authentication and Access Container for 'Shiny' and 'webR' |
|---|---|
| Description: | Authentication and access gate for 'Shiny' applications, with two deployment variants sharing one package: an external/no-login gate for apps running in the browser with 'webR' (identity delegated to a provider such as Auth0), and a local/server variant with credential login against a 'duckdb' user store, Argon2id password hashing and Pushover two-factor authentication. The authentication UI is built with Material UI. Originally derived from the 'shinymanager' package (GPL-3). |
| Authors: | Sergio Ciordia [aut, cre] |
| Maintainer: | Sergio Ciordia <[email protected]> |
| License: | GPL-3 |
| Version: | 0.7.0 |
| Built: | 2026-12-03 12:55:45 UTC |
| Source: | https://github.com/sciordia/authlas |
Insert a user, hashing the password with Argon2id and encrypting
the Pushover user key with the master key (AUTHLAS_KEY).
Server-only; never used in webR.
add_user( dbdir, email, password, pushover_user_key = NULL, name = NULL, role = "user", profile = list(), twofa_enabled = TRUE, device_ttl_hours = NULL, user_id = NULL )add_user( dbdir, email, password, pushover_user_key = NULL, name = NULL, role = "user", profile = list(), twofa_enabled = TRUE, device_ttl_hours = NULL, user_id = NULL )
dbdir |
Path to the duckdb file, or an open DBIConnection. |
email |
User email (login id, unique). Stored trimmed and in lower case; an email that differs from an existing one only in case is refused. |
password |
Plain-text password (hashed before storage). |
pushover_user_key |
The user's Pushover user key (encrypted before storage). Required to deliver the 2FA code. |
name |
Optional display name. |
role |
Optional role string. |
profile |
Optional named list of extra profile fields, stored as JSON and exposed to the session after login. |
twofa_enabled |
Whether this user must complete the Pushover two-factor
step after a valid password. |
device_ttl_hours |
Per-user lifetime (in hours) of the "remember this
device" token that skips 2FA on later logins. |
user_id |
Optional explicit user id (defaults to a random token). |
Invisibly, the user_id.
Verifies the current password of a user that is already identified, e.g.
before changing the password or disabling 2FA in an account page. Unlike
check_credentials_local(), it accepts a user_id and, by
default, counts failures with the same counter and lockout as the login
screen, so a stolen session cannot try passwords without limit from there.
Server-only; never used in webR.
check_password( dbdir, user, password, lockout = TRUE, max_failures = 5, lockout_minutes = 15 )check_password( dbdir, user, password, lockout = TRUE, max_failures = 5, lockout_minutes = 15 )
dbdir |
Path to the duckdb file, or an open DBIConnection. |
user |
The user's |
password |
The password to check. |
lockout |
Whether failures count towards (and are refused by) the
login lockout. |
max_failures, lockout_minutes
|
Lockout policy, as
|
With lockout = TRUE a wrong password adds a failure to the user's
email (table login_attempts, shared with the login) and a right one
clears them. After max_failures failures the email is locked for
lockout_minutes: the login is refused too, and check_password()
returns FALSE without checking, with attribute
"locked_minutes" (minutes left, an integer >= 1) so the app can show
the login_locked message (see local_messages()). Pass
the same max_login_failures / lockout_minutes as to
secure_server_local() if you changed them there.
An unknown user gives FALSE after verifying against a dummy hash, so
it takes the same time as a wrong password.
TRUE if the password is right, FALSE otherwise; while
locked (including right after the failure that locks), FALSE with
attribute "locked_minutes".
## Not run: ok <- check_password(db, auth$user_id, input$current_password) if (!is.null(attr(ok, "locked_minutes"))) { msg <- sprintf(local_messages()$login_locked, attr(ok, "locked_minutes")) } else if (isTRUE(ok)) { set_password(db, auth$user_id, input$new_password, except = current_token()) } ## End(Not run)## Not run: ok <- check_password(db, auth$user_id, input$current_password) if (!is.null(attr(ok, "locked_minutes"))) { msg <- sprintf(local_messages()$login_locked, attr(ok, "locked_minutes")) } else if (isTRUE(ok)) { set_password(db, auth$user_id, input$new_password, except = current_token()) } ## End(Not run)
Create the duckdb file and the authentication tables used by the
local (server) variant: users, twofa_codes,
device_tokens, login_attempts and twofa_sends. Server-only; never used in
webR.
create_user_db(dbdir, overwrite = FALSE)create_user_db(dbdir, overwrite = FALSE)
dbdir |
Path to the duckdb file. |
overwrite |
If |
Invisibly, dbdir.
Session token of the current session
current_token(session = shiny::getDefaultReactiveDomain())current_token(session = shiny::getDefaultReactiveDomain())
session |
Shiny session. |
The session token of an authenticated session (the one authlas
minted at login), or NULL if the session is not authenticated or
its token is no longer valid.
See all labels registered with get_labels(),
then set custom text with set_labels().
set_labels(language, ...) get_labels(language = "en")set_labels(language, ...) get_labels(language = "en")
language |
Language to use for labels, supported values are : "en", "fr", "pt-BR", "es", "de", "pl", "ja", "el", "id", "zh-CN", "no". |
... |
A named list with labels to replace or several named argument |
get_labels() return a named list with all labels registered.
# In global.R for example: set_labels( language = "en", "Please authenticate" = "You have to login", "Username:" = "What's your name:", "Password:" = "Enter your password:" ) # same with named list set_labels( language = "en", list( "Please authenticate" = "You have to login", "Username:" = "What's your name:", "Password:" = "Enter your password:" ) )# In global.R for example: set_labels( language = "en", "Please authenticate" = "You have to login", "Username:" = "What's your name:", "Password:" = "Enter your password:" ) # same with named list set_labels( language = "en", list( "Please authenticate" = "You have to login", "Username:" = "What's your name:", "Password:" = "Enter your password:" ) )
Authenticated symmetric encryption used to store each user's
Pushover user key, which must later be decrypted to send the 2FA
notification. It uses libsodium's secretbox (XSalsa20-Poly1305, via the
sodium package): a value that was altered, or encrypted with another
master key, fails to decrypt instead of producing garbage. The master key
is read from the AUTHLAS_KEY environment variable (the legacy
SHINYMANAGER_KEY is still honored as a fallback). Never called in
webR.
decrypt_secret() also reads the unauthenticated AES-CBC format
written by authlas < 0.6; reencrypt_secrets() rewrites every stored
Pushover key of a database in the current format.
encrypt_secret(x) decrypt_secret(stored) reencrypt_secrets(dbdir)encrypt_secret(x) decrypt_secret(stored) reencrypt_secrets(dbdir)
x |
A plain-text secret to encrypt. |
stored |
A string previously produced by |
dbdir |
Path to the duckdb file, or an open DBIConnection. |
encrypt_secret() returns a "v2:nonce:ciphertext"
(base64) string. decrypt_secret() returns the original plain text,
and stops with an error if the value was tampered with or the master key is
wrong. reencrypt_secrets() returns, invisibly, the number of keys
rewritten.
Use these helpers when authentication is handled before Shiny, for example by Auth0 or Cloudflare Access. In this mode shinymanager only creates its session token and applies lightweight authorization rules.
secure_app_external( ui, waiting_ui = NULL, head_auth = NULL, theme = NULL, language = "en", timeout = TRUE, page_args = NULL, logout_button = TRUE ) check_credentials_external( allowed_users = NULL, allowed_domains = NULL, require_verified_email = FALSE, user_info = NULL ) secure_server_external( check_credentials = check_credentials_external(), external_input = "auth0_user", logout_url = NULL, logout_callback = NULL, timeout = 15, timeout_warning = 1, keep_token = FALSE, session = shiny::getDefaultReactiveDomain() )secure_app_external( ui, waiting_ui = NULL, head_auth = NULL, theme = NULL, language = "en", timeout = TRUE, page_args = NULL, logout_button = TRUE ) check_credentials_external( allowed_users = NULL, allowed_domains = NULL, require_verified_email = FALSE, user_info = NULL ) secure_server_external( check_credentials = check_credentials_external(), external_input = "auth0_user", logout_url = NULL, logout_callback = NULL, timeout = 15, timeout_warning = 1, keep_token = FALSE, session = shiny::getDefaultReactiveDomain() )
ui |
UI of the application. |
waiting_ui |
UI shown while waiting for the external identity. |
head_auth |
Tags to add to the authentication page head, typically Auth0 scripts. |
theme |
Deprecated and ignored. The authentication page is now built
with |
language |
Language used for shinymanager metadata. |
timeout |
For |
page_args |
Named list of options passed to
|
logout_button |
Whether to show the floating logout button in the
authenticated app. Set it to |
allowed_users |
Character vector of allowed emails or user ids. |
allowed_domains |
Character vector of allowed email domains. |
require_verified_email |
Require |
user_info |
Optional function receiving the normalized external identity
and returning extra fields to expose in |
check_credentials |
Function returned by |
external_input |
Shiny input id populated by JavaScript with the external
identity. A character email/user id or a list with |
logout_url |
URL to navigate to after shinymanager removes its local
token. For Auth0 this is usually the |
logout_callback |
Name of a JavaScript function on |
timeout_warning |
Minutes before the inactivity timeout at which a
dialog warns that the session is about to end, with a "Continue" button
that keeps it open; any real activity on the page does the same. At
most half of |
keep_token |
Logical, keep the token used to authenticate in the URL. |
session |
Shiny session. |
secure_app_external() returns a UI function.
secure_server_external() returns reactive values with user
information.
welcome_panel. A runnable example app:
system.file("examples", "welcome_webr.R", package = "authlas").
Create a fixed button in page corner with additional button(s) in it
fab_button( ..., position = c("bottom-right", "top-right", "bottom-left", "top-left", "none"), animation = c("slidein", "slidein-spring", "fountain", "zoomin"), toggle = c("hover", "click"), inputId = NULL, label = NULL )fab_button( ..., position = c("bottom-right", "top-right", "bottom-left", "top-left", "none"), animation = c("slidein", "slidein-spring", "fountain", "zoomin"), toggle = c("hover", "click"), inputId = NULL, label = NULL )
... |
|
position |
Position for the button. |
animation |
Animation when displaying floating buttons. |
toggle |
Display floating buttons when main button is clicked or hovered. |
inputId |
Id for the FAB button (act like an |
label |
Label for main button. |
library(shiny) library(authlas) ui <- fluidPage( tags$h1("FAB button"), tags$p("FAB button:"), verbatimTextOutput(outputId = "res_fab"), tags$p("Logout button:"), verbatimTextOutput(outputId = "res_logout"), tags$p("Info button:"), verbatimTextOutput(outputId = "res_info"), fab_button( actionButton( inputId = "logout", label = "Logout", icon = icon("arrow-right-from-bracket") ), actionButton( inputId = "info", label = "Information", icon = icon("info") ), inputId = "fab" ) ) server <- function(input, output, session) { output$res_fab <- renderPrint({ input$fab }) output$res_logout <- renderPrint({ input$logout }) output$res_info <- renderPrint({ input$info }) } if (interactive()) { shinyApp(ui, server) }library(shiny) library(authlas) ui <- fluidPage( tags$h1("FAB button"), tags$p("FAB button:"), verbatimTextOutput(outputId = "res_fab"), tags$p("Logout button:"), verbatimTextOutput(outputId = "res_logout"), tags$p("Info button:"), verbatimTextOutput(outputId = "res_info"), fab_button( actionButton( inputId = "logout", label = "Logout", icon = icon("arrow-right-from-bracket") ), actionButton( inputId = "info", label = "Information", icon = icon("info") ), inputId = "fab" ) ) server <- function(input, output, session) { output$res_fab <- renderPrint({ input$fab }) output$res_logout <- renderPrint({ input$logout }) output$res_info <- renderPrint({ input$info }) } if (interactive()) { shinyApp(ui, server) }
One-way password hashing and verification with Argon2id (via the
sodium package), used by the local credentials variant. Never called
in webR.
hash_password(password) verify_password(password, hash)hash_password(password) verify_password(password, hash)
password |
A plain-text password. |
hash |
An Argon2id hash previously produced by |
hash_password() returns an Argon2id hash string.
verify_password() returns a logical.
Returns the texts that secure_server_local() shows on the
login/2FA screens and sends through Pushover. Defaults are in Spanish; pass
any subset to override it, either here or directly as
secure_server_local(messages = list(...)).
local_messages(...)local_messages(...)
... |
Named messages to override. Valid names:
|
A named list with every message.
local_messages(invalid_credentials = "Wrong email or password.", wrong_code_many = "Wrong code. %d attempts left.")local_messages(invalid_credentials = "Wrong email or password.", wrong_code_many = "Wrong code. %d attempts left.")
Use these helpers when the application runs on a server (not webR) and you want credential-based login with a duckdb user store and Pushover two-factor authentication. The application code is not exposed to the browser, so a real login form is shown. Passwords are hashed with Argon2id and the per-user Pushover key is stored encrypted. All heavy dependencies are Suggests.
check_credentials_local(db, allowed_roles = NULL) secure_app_local( ui, theme = NULL, language = "en", timeout = TRUE, twofa_window = 30, head_auth = NULL, login_ui = NULL, twofa_ui = NULL, page_args = NULL, logout_button = TRUE, device_cookie = "shinymanager_device" ) secure_server_local( check_credentials, db, pushover_app_token = Sys.getenv("PUSHOVER_APP"), pushover_title = NULL, twofa_window = 30, max_attempts = 3, remember_device = TRUE, device_ttl_hours = 24, timeout = 15, max_login_failures = 5, lockout_minutes = 15, max_resends = 3, max_sends = 5, send_window_minutes = 15, timeout_warning = 1, messages = NULL, session = shiny::getDefaultReactiveDomain() )check_credentials_local(db, allowed_roles = NULL) secure_app_local( ui, theme = NULL, language = "en", timeout = TRUE, twofa_window = 30, head_auth = NULL, login_ui = NULL, twofa_ui = NULL, page_args = NULL, logout_button = TRUE, device_cookie = "shinymanager_device" ) secure_server_local( check_credentials, db, pushover_app_token = Sys.getenv("PUSHOVER_APP"), pushover_title = NULL, twofa_window = 30, max_attempts = 3, remember_device = TRUE, device_ttl_hours = 24, timeout = 15, max_login_failures = 5, lockout_minutes = 15, max_resends = 3, max_sends = 5, send_window_minutes = 15, timeout_warning = 1, messages = NULL, session = shiny::getDefaultReactiveDomain() )
db |
Path to the duckdb file, or an open DBIConnection. |
allowed_roles |
Optional character vector of roles allowed to log in. If
|
ui |
UI of the application (shown once authenticated). |
theme |
Deprecated and ignored. The authentication page is now built
with |
language |
Language used for shinymanager metadata. |
timeout |
For |
twofa_window |
Seconds the 2FA code stays valid. |
head_auth |
Tags to add to the authentication page head. |
login_ui, twofa_ui
|
Custom login and 2FA screens. |
page_args |
Named list of options passed to
|
logout_button |
Whether to show the floating logout button in the
authenticated app. Set it to |
device_cookie |
Name of the "remember this device" cookie. The cookie is already scoped to the app's path; give each app its own name when several authlas apps share the same host and path (e.g. on different ports, which cookies do not distinguish). |
check_credentials |
Function returned by |
pushover_app_token |
Pushover application (API) token used to deliver the 2FA code. Per-user keys are stored encrypted in the database. |
pushover_title |
Title of the Pushover notification. If |
max_attempts |
Maximum wrong 2FA attempts before returning to login. |
remember_device |
If |
device_ttl_hours |
Default lifetime of the device cookie/token, in hours,
used for users that have no per-user |
max_login_failures, lockout_minutes
|
Password throttling: after
|
max_resends |
Maximum "Resend" clicks per login attempt; one more sends
the user back to the login screen with |
max_sends, send_window_minutes
|
At most |
timeout_warning |
Minutes before the inactivity timeout at which a
dialog warns that the session is about to end, with a button
( |
messages |
Texts shown to the user and sent through Pushover: a named
list overriding any subset of |
session |
Shiny session. |
check_credentials_local() returns a validation function that
takes user (email) and password and returns a list with
result, expired, authorized, user_info, and the
per-user policy fields twofa_enabled (logical) and
device_ttl_hours (numeric or NA). The policy fields are kept
out of user_info (which is exposed to the app and stored in the
session token).
secure_app_local() returns a UI function.
secure_server_local() returns reactive values with user
information.
A runnable example app:
system.file("examples", "local_auth.R", package = "authlas").
Building blocks of the login and two-factor screens shown by
secure_app_local(). local_login_ui() and
local_twofa_ui() are the default screens (their texts can be changed
through the arguments); pass them, or your own UI, to the login_ui /
twofa_ui arguments of secure_app_local().
local_centered(...) local_login_ui( title = "Acceso", email_label = "Email", password_label = "Contraseña", login_label = "Acceder", cancel_label = "Cancelar" ) local_twofa_cells() local_twofa_timer(seconds = 30, label = "Caduca en %s s") local_twofa_ui( seconds = 30, title = "Verificación en dos pasos", instructions = paste0("Introduce el código de 6 dígitos que ", "has recibido en tu dispositivo."), expires_label = "Caduca en %s s", submit_label = "Validar", resend_label = "Reenviar", cancel_label = "Cancelar" )local_centered(...) local_login_ui( title = "Acceso", email_label = "Email", password_label = "Contraseña", login_label = "Acceder", cancel_label = "Cancelar" ) local_twofa_cells() local_twofa_timer(seconds = 30, label = "Caduca en %s s") local_twofa_ui( seconds = 30, title = "Verificación en dos pasos", instructions = paste0("Introduce el código de 6 dígitos que ", "has recibido en tu dispositivo."), expires_label = "Caduca en %s s", submit_label = "Validar", resend_label = "Reenviar", cancel_label = "Cancelar" )
... |
Elements placed in the centered card. |
title, instructions
|
Screen heading and (2FA) explanatory text. |
email_label, password_label
|
Labels of the credential fields. |
login_label, cancel_label, submit_label, resend_label
|
Button labels. |
seconds |
Seconds shown by the countdown (match the server's
|
label |
Countdown text for |
expires_label |
Text of the countdown; |
A UI tag (list).
A custom screen can use any layout or components (muiMaterial is
recommended, since the auth page is a muiMaterialPage()), as long as
it carries the input/output ids that secure_server_local()
listens to:
Login screen (login_ui)
sm_emailText input with the email (e.g.
muiMaterial::TextField.shinyInput("sm_email", ...)). Required.
sm_passwordPassword input. Required.
sm_loginButton that submits the credentials. Required.
sm_login_errortextOutput() for the login errors.
Required.
sm_cancelButton that clears both fields. Optional.
2FA screen (twofa_ui)
sm_2fa_1 ... sm_2fa_6
The six code cells (class
sm-2fa-cell); use local_twofa_cells(). They are assembled
into input$sm_2fa_code by the bundled JavaScript. Required.
sm_2fa_submitButton that validates the code. Required.
sm_twofa_errortextOutput() for the 2FA errors.
Required.
sm_2fa_resendButton that sends a new code. Optional.
sm_2fa_cancelButton that returns to the login screen. Optional.
sm-2fa-timerCountdown element; use
local_twofa_timer(). Optional.
Pressing Enter in sm_email / sm_password submits the login, and
pressing Enter in a code cell submits the 2FA code. The current field values
are sent to the server before the submit event (muiMaterial text fields
otherwise report their value with a 250 ms delay), so this works with any
input whose DOM element carries the documented id.
# Default screens with English texts login <- local_login_ui(title = "Sign in", password_label = "Password", login_label = "Sign in", cancel_label = "Clear") # A fully custom 2FA screen twofa <- function(seconds) { local_centered( muiMaterial::Typography("Enter your code", variant = "h5"), local_twofa_cells(), local_twofa_timer(seconds, label = "Expires in %s s"), shiny::textOutput("sm_twofa_error"), muiMaterial::Button.shinyInput("sm_2fa_submit", "Verify", variant = "contained") ) }# Default screens with English texts login <- local_login_ui(title = "Sign in", password_label = "Password", login_label = "Sign in", cancel_label = "Clear") # A fully custom 2FA screen twofa <- function(seconds) { local_centered( muiMaterial::Typography("Enter your code", variant = "h5"), local_twofa_cells(), local_twofa_timer(seconds, label = "Expires in %s s"), shiny::textOutput("sm_twofa_error"), muiMaterial::Button.shinyInput("sm_2fa_submit", "Verify", variant = "contained") ) }
Does exactly what the floating logout button does: forgets the session
token and returns to the access page (or, for the external variant, follows
logout_url / logout_callback). Use it from your own menu when
the floating button is hidden with logout_button = FALSE.
logout(session = shiny::getDefaultReactiveDomain())logout(session = shiny::getDefaultReactiveDomain())
session |
Shiny session (managed by |
Invisibly, NULL.
## Not run: observeEvent(input$my_logout, logout(session)) ## End(Not run)## Not run: observeEvent(input$my_logout, logout(session)) ## End(Not run)
Read and change users without touching authlas' tables directly.
user is either the user_id or the email (case-insensitive).
Server-only; never used in webR.
get_user(dbdir, user) list_users(dbdir, role = NULL) set_password(dbdir, user, password, revoke = TRUE, except = NULL) set_role(dbdir, user, role) set_name(dbdir, user, name) set_twofa(dbdir, user, pushover_user_key) get_pushover_key(dbdir, user) count_devices(dbdir, user) forget_devices(dbdir, user) delete_user(dbdir, user)get_user(dbdir, user) list_users(dbdir, role = NULL) set_password(dbdir, user, password, revoke = TRUE, except = NULL) set_role(dbdir, user, role) set_name(dbdir, user, name) set_twofa(dbdir, user, pushover_user_key) get_pushover_key(dbdir, user) count_devices(dbdir, user) forget_devices(dbdir, user) delete_user(dbdir, user)
dbdir |
Path to the duckdb file, or an open DBIConnection. |
user |
The user's |
role |
For |
password |
The new plain-text password. |
revoke |
Whether |
except |
Session tokens to keep open when revoking. |
name |
The new display name, or |
pushover_user_key |
The user's Pushover user key, or |
get_user() returns the user's public data (never the password
hash nor the Pushover key), or NULL if there is no such user.
list_users() returns the same data for every user (without
profile) as a data frame, ordered by name (or email when there is
no name), optionally only those with a given role
(case-insensitive).
set_password() replaces the password (hashed with Argon2id),
clears any login lockout of that email and, with revoke = TRUE,
closes the user's open sessions (revoke_sessions), except
the tokens in except (e.g. current_token()).
set_role() changes the role. Open sessions keep the role they
logged in with; call revoke_sessions() to force a new login.
set_name() changes the display name (trimmed); NULL,
NA or "" remove it, so the login uses the email as the
name. Open sessions keep the user_info they logged in with.
set_twofa() enables two-factor authentication with the given
Pushover user key (stored encrypted), or disables it and deletes the key
(and any pending code) when pushover_user_key = NULL.
get_pushover_key() returns the user's Pushover user key,
decrypted, or NULL if they have none: for the app's own
notifications, or to show it masked. It returns a secret: use
it only on the server, and never send it whole to the browser (show e.g.
only its last 4 characters). A key stored by authlas < 0.6 is rewritten
in the current format on the way. If the key cannot be decrypted (another
AUTHLAS_KEY, or altered data) it stops with the error of
decrypt_secret(), which never contains the secret.
count_devices() counts the user's remembered devices that are
still valid; forget_devices() deletes all of them, so the next
login asks for the 2FA code again.
delete_user() deletes the user with their devices, pending
codes and counters, and revokes their sessions.
set_user_settings() changes twofa_enabled and
device_ttl_hours.
get_user(): a list with user_id, email,
name, role, profile (list), twofa_enabled,
device_ttl_hours, has_pushover_key and created_at, or
NULL. list_users(): a data frame with columns user_id,
email, name (NA if unset), role,
twofa_enabled (logical; TRUE when unset in the database),
device_ttl_hours (numeric; NA = the server default),
has_pushover_key (logical) and created_at (epoch seconds);
0 rows, with those columns, when there are no users.
get_pushover_key(): a string or NULL.
count_devices(): an integer. forget_devices():
invisibly, the number of devices deleted. delete_user():
invisibly, TRUE if the user existed. The setters: invisibly, the
user_id; they stop with an error if the user does not exist.
## Not run: db <- "users.duckdb" get_user(db, "[email protected]") list_users(db, role = "admin") set_password(db, "[email protected]", "N3w-secret", except = current_token()) set_role(db, "[email protected]", "admin") set_name(db, "[email protected]", "Ana L\u00f3pez") set_twofa(db, "[email protected]", pushover_user_key = "<key>") key <- get_pushover_key(db, "[email protected]") # server-side only if (!is.null(key)) paste0("\u2022\u2022\u2022\u2022", substring(key, nchar(key) - 3)) forget_devices(db, "[email protected]") delete_user(db, "[email protected]") ## End(Not run)## Not run: db <- "users.duckdb" get_user(db, "[email protected]") list_users(db, role = "admin") set_password(db, "[email protected]", "N3w-secret", except = current_token()) set_role(db, "[email protected]", "admin") set_name(db, "[email protected]", "Ana L\u00f3pez") set_twofa(db, "[email protected]", pushover_user_key = "<key>") key <- get_pushover_key(db, "[email protected]") # server-side only if (!is.null(key)) paste0("\u2022\u2022\u2022\u2022", substring(key, nchar(key) - 3)) forget_devices(db, "[email protected]") delete_user(db, "[email protected]") ## End(Not run)
Removes every session token of a user, so all of their open sessions are closed (sent back to the access page) right away, and their tokens can no longer be used. Typical uses: after a password change ("log out the other sessions"), a role change, or when removing a user.
revoke_sessions(user_id, except = NULL)revoke_sessions(user_id, except = NULL)
user_id |
The user whose sessions are revoked: the |
except |
Token(s) to keep, typically |
The number of sessions revoked.
## Not run: # in the server, after the user changed their password: revoke_sessions(auth$user_id, except = current_token()) ## End(Not run)## Not run: # in the server, after the user changed their password: revoke_sessions(auth$user_id, except = current_token()) ## End(Not run)
Change the per-user two-factor and device-remember settings of an existing user, in place. Server-only; never used in webR.
set_user_settings( dbdir, user, twofa_enabled = NULL, device_ttl_hours = NULL, email = NULL )set_user_settings( dbdir, user, twofa_enabled = NULL, device_ttl_hours = NULL, email = NULL )
dbdir |
Path to the duckdb file, or an open DBIConnection. |
user |
The user's |
twofa_enabled |
|
device_ttl_hours |
|
email |
Deprecated alias of |
Invisibly, the user_id. Stops with an error if the user does
not exist.
See all labels registered with get_labels(),
then set custom text with set_labels().
use_language(lan = "en")use_language(lan = "en")
lan |
Language to use for labels, supported values are : "en", "fr", "pt-BR", "es", "de", "pl", "ja", "el", "id", "zh-CN", "no". |
A language object
use_language(lan = "fr")use_language(lan = "fr")
Build an editable welcome screen, rendered with 'muiMaterial'
(Material UI), to use as the waiting_ui of
secure_app_external in the webR variant. There is no login
form: the application code runs in the browser, so access is only gated by a
single button. Clicking the button pushes a (configurable) identity into
Shiny via Shiny.setInputValue(), which secure_server_external
then authorizes. The application HTML stays hidden inside the container until
the button is pressed.
welcome_panel( ..., logo = NULL, button_label = "Acceder", button_id = "no_login", identity = list(user = "guest", name = "Invitado", auth_provider = "none"), button_props = list(variant = "contained", size = "large", color = "primary"), max_width = 520 )welcome_panel( ..., logo = NULL, button_label = "Acceder", button_id = "no_login", identity = list(user = "guest", name = "Invitado", auth_provider = "none"), button_props = list(variant = "contained", size = "large", color = "primary"), max_width = 520 )
... |
Static content to display between the logo and the button. Any
'muiMaterial' component or |
logo |
Optional logo. Either a URL/path (character, rendered as an
|
button_label |
Text of the access button. |
button_id |
Shiny input id the button writes to. Must match the
|
identity |
Named list pushed as the external identity when the button is
clicked (e.g. |
button_props |
Named list of extra props forwarded to the 'muiMaterial'
|
max_width |
Maximum width (px) of the centered content column. |
A shiny.tag suitable as the waiting_ui argument of
secure_app_external.
secure_app_external. A runnable example app:
system.file("examples", "welcome_webr.R", package = "authlas").
if (interactive()) { library(shiny) library(authlas) ui <- secure_app_external( ui = tagList( muiMaterial::CssBaseline(), muiMaterial::Box( sx = list(p = 3), muiMaterial::Typography("App protegida", variant = "h4"), verbatimTextOutput("auth") ) ), waiting_ui = welcome_panel( muiMaterial::Typography("Bienvenido a la aplicacion", variant = "h5"), logo = "https://www.r-project.org/logo/Rlogo.png", button_label = "Acceder", button_id = "no_login" ) ) server <- function(input, output, session) { auth <- secure_server_external( check_credentials = check_credentials_external(), external_input = "no_login", timeout = 0 ) output$auth <- renderPrint(reactiveValuesToList(auth)) } shinyApp(ui, server) }if (interactive()) { library(shiny) library(authlas) ui <- secure_app_external( ui = tagList( muiMaterial::CssBaseline(), muiMaterial::Box( sx = list(p = 3), muiMaterial::Typography("App protegida", variant = "h4"), verbatimTextOutput("auth") ) ), waiting_ui = welcome_panel( muiMaterial::Typography("Bienvenido a la aplicacion", variant = "h5"), logo = "https://www.r-project.org/logo/Rlogo.png", button_label = "Acceder", button_id = "no_login" ) ) server <- function(input, output, session) { auth <- secure_server_external( check_credentials = check_credentials_external(), external_input = "no_login", timeout = 0 ) output$auth <- renderPrint(reactiveValuesToList(auth)) } shinyApp(ui, server) }