Package 'authlas'

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

Help Index


Add a user to the local credentials database

Description

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.

Usage

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
)

Arguments

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. TRUE (default) keeps the 2FA challenge; FALSE logs the user straight into the app once credentials match. Stored per user in the database.

device_ttl_hours

Per-user lifetime (in hours) of the "remember this device" token that skips 2FA on later logins. NULL (default) means the user has no override and the server's device_ttl_hours applies.

user_id

Optional explicit user id (defaults to a random token).

Value

Invisibly, the user_id.


Check the password of a known user

Description

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.

Usage

check_password(
  dbdir,
  user,
  password,
  lockout = TRUE,
  max_failures = 5,
  lockout_minutes = 15
)

Arguments

dbdir

Path to the duckdb file, or an open DBIConnection.

user

The user's user_id or email.

password

The password to check.

lockout

Whether failures count towards (and are refused by) the login lockout. FALSE only checks, e.g. in admin scripts.

max_failures, lockout_minutes

Lockout policy, as max_login_failures / lockout_minutes of secure_server_local().

Details

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.

Value

TRUE if the password is right, FALSE otherwise; while locked (including right after the failure that locks), FALSE with attribute "locked_minutes".

Examples

## 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 local credentials database

Description

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.

Usage

create_user_db(dbdir, overwrite = FALSE)

Arguments

dbdir

Path to the duckdb file.

overwrite

If TRUE, drop existing authentication tables first.

Value

Invisibly, dbdir.


Session token of the current session

Description

Session token of the current session

Usage

current_token(session = shiny::getDefaultReactiveDomain())

Arguments

session

Shiny session.

Value

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 Also

revoke_sessions


Modify shinymanager labels to use custom text

Description

See all labels registered with get_labels(), then set custom text with set_labels().

Usage

set_labels(language, ...)

get_labels(language = "en")

Arguments

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

Value

get_labels() return a named list with all labels registered.

Examples

# 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:"
 )
)

Reversible encryption of a user secret (server variant)

Description

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.

Usage

encrypt_secret(x)

decrypt_secret(stored)

reencrypt_secrets(dbdir)

Arguments

x

A plain-text secret to encrypt.

stored

A string previously produced by encrypt_secret().

dbdir

Path to the duckdb file, or an open DBIConnection.

Value

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.


External authentication helpers

Description

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.

Usage

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()
)

Arguments

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 muiMaterial::muiMaterialPage() (Material UI), which suppresses Bootstrap; this argument no longer applies.

language

Language used for shinymanager metadata.

timeout

For secure_app_external, logical; whether to include the inactivity-timeout script. For secure_server_external, inactivity timeout in minutes before logout (0 disables). Only real user activity on the page (mouse, keyboard, wheel, scrolling, touches) renews the session; automatic refreshes (invalidateLater, reactivePoll, outputs recalculating) do not, so an idle session expires even if the app keeps updating itself. Activity is reported at most once every 15 s; the server checks for expiry every 30 s.

page_args

Named list of options passed to muiMaterial::muiMaterialPage() for the authentication page, e.g. list(useMaterialIconsFilled = TRUE) to load the Material Icons font (needed by muiMaterial::Icon() ligatures in custom screens). useFontRoboto defaults to TRUE; suppressBootstrap cannot be changed.

logout_button

Whether to show the floating logout button in the authenticated app. Set it to FALSE to provide your own control and call logout(session) from the server.

allowed_users

Character vector of allowed emails or user ids.

allowed_domains

Character vector of allowed email domains.

require_verified_email

Require email_verified = TRUE when the external identity payload contains that field.

user_info

Optional function receiving the normalized external identity and returning extra fields to expose in user_info.

check_credentials

Function returned by check_credentials_external.

external_input

Shiny input id populated by JavaScript with the external identity. A character email/user id or a list with email, user, name, sub, and email_verified is accepted.

logout_url

URL to navigate to after shinymanager removes its local token. For Auth0 this is usually the /v2/logout URL.

logout_callback

Name of a JavaScript function on window to call after shinymanager removes its local token. Used when Auth0 logout is handled by the browser SDK.

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 timeout. 0 disables the warning. The texts follow language (labels "Your session will end in %s seconds due to inactivity." and "Continue", see set_labels).

keep_token

Logical, keep the token used to authenticate in the URL.

session

Shiny session.

Value

secure_app_external() returns a UI function. secure_server_external() returns reactive values with user information.

See Also

welcome_panel. A runnable example app: system.file("examples", "welcome_webr.R", package = "authlas").


Create a FAB button

Description

Create a fixed button in page corner with additional button(s) in it

Usage

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
)

Arguments

...

actionButtons to be used as floating buttons.

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 actionButton).

label

Label for main button.

Examples

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)
}

Password hashing (server variant)

Description

One-way password hashing and verification with Argon2id (via the sodium package), used by the local credentials variant. Never called in webR.

Usage

hash_password(password)

verify_password(password, hash)

Arguments

password

A plain-text password.

hash

An Argon2id hash previously produced by hash_password().

Value

hash_password() returns an Argon2id hash string. verify_password() returns a logical.


Messages of the local (server) authentication flow

Description

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(...)).

Usage

local_messages(...)

Arguments

...

Named messages to override. Valid names:

invalid_credentials

Wrong email/password or unauthorized user.

login_locked

Too many failed logins for this email or session; %d is replaced by the minutes left.

send_failed

The 2FA code could not be delivered.

resend_failed

The 2FA code could not be re-delivered.

code_invalid

No pending/already used code (back to login).

too_many_attempts

Attempt limit reached (back to login).

code_expired

The code is older than twofa_window.

wrong_code_one

Wrong code, one attempt left.

wrong_code_many

Wrong code, several attempts left; %d is replaced by the number.

pushover_message

Body of the Pushover notification; %s is replaced by the code (must be present).

timeout_warning

Dialog shown timeout_warning minutes before the inactivity timeout; %s is replaced by the seconds left (counting down).

timeout_continue

Button of that dialog that keeps the session open.

Value

A named list with every message.

Examples

local_messages(invalid_credentials = "Wrong email or password.",
               wrong_code_many = "Wrong code. %d attempts left.")

Local (server) authentication helpers

Description

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.

Usage

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()
)

Arguments

db

Path to the duckdb file, or an open DBIConnection.

allowed_roles

Optional character vector of roles allowed to log in. If NULL, any user in the database may log in.

ui

UI of the application (shown once authenticated).

theme

Deprecated and ignored. The authentication page is now built with muiMaterial::muiMaterialPage() (Material UI), which suppresses Bootstrap; this argument no longer applies.

language

Language used for shinymanager metadata.

timeout

For secure_app_local, logical; whether to include the inactivity-timeout script. For secure_server_local, inactivity timeout in minutes (0 disables). Only real user activity on the page (mouse, keyboard, wheel, scrolling, touches) renews the session; automatic refreshes (invalidateLater, reactivePoll, outputs recalculating) do not, so an idle session expires even if the app keeps updating itself. Activity is reported at most once every 15 s; the server checks for expiry every 30 s.

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. NULL (default) uses local_login_ui() / local_twofa_ui(). Either a UI tag, or a function returning one; a twofa_ui function that takes an argument receives twofa_window (seconds). Custom screens must carry the ids listed in local-screens; a warning names any required id that is missing.

page_args

Named list of options passed to muiMaterial::muiMaterialPage() for the authentication page, e.g. list(useMaterialIconsFilled = TRUE) to load the Material Icons font (needed by muiMaterial::Icon() ligatures in custom screens). useFontRoboto defaults to TRUE; suppressBootstrap cannot be changed.

logout_button

Whether to show the floating logout button in the authenticated app. Set it to FALSE to provide your own control and call logout(session) from the server.

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 check_credentials_local.

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 NULL, a default title is used.

max_attempts

Maximum wrong 2FA attempts before returning to login.

remember_device

If TRUE, a valid device cookie skips 2FA.

device_ttl_hours

Default lifetime of the device cookie/token, in hours, used for users that have no per-user device_ttl_hours of their own (see add_user/set_user_settings). Whether 2FA is required at all is also decided per user (twofa_enabled); users with 2FA disabled log in straight after a valid password.

max_login_failures, lockout_minutes

Password throttling: after max_login_failures failed logins for the same email (counted in the database, so it survives reloads and new sessions) or in the same session, further attempts are refused for lockout_minutes without checking the password, and login_locked is shown. Unknown emails are counted and answered exactly like wrong passwords. Use max_login_failures = Inf to disable.

max_resends

Maximum "Resend" clicks per login attempt; one more sends the user back to the login screen with too_many_attempts.

max_sends, send_window_minutes

At most max_sends 2FA codes are delivered to the same user within send_window_minutes (counted in the database, across sessions). Beyond that the user goes back to the login screen with login_locked until the window frees up.

timeout_warning

Minutes before the inactivity timeout at which a dialog warns that the session is about to end, with a button (timeout_continue) that keeps it open; any real activity on the page does the same. At most half of timeout. 0 disables the warning. Texts: timeout_warning and timeout_continue in local_messages().

messages

Texts shown to the user and sent through Pushover: a named list overriding any subset of local_messages() (e.g. list(invalid_credentials = "Wrong email or password.")). Unknown names are an error.

session

Shiny session.

Value

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.

See Also

A runnable example app: system.file("examples", "local_auth.R", package = "authlas").


Screens of the local (server) authentication page

Description

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().

Usage

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"
)

Arguments

...

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 twofa_window).

label

Countdown text for local_twofa_timer(); %s is replaced by the live number of seconds.

expires_label

Text of the countdown; %s is replaced by the live number of seconds.

Value

A UI tag (list).

Building your own screens

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_email

Text input with the email (e.g. muiMaterial::TextField.shinyInput("sm_email", ...)). Required.

sm_password

Password input. Required.

sm_login

Button that submits the credentials. Required.

sm_login_error

textOutput() for the login errors. Required.

sm_cancel

Button 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_submit

Button that validates the code. Required.

sm_twofa_error

textOutput() for the 2FA errors. Required.

sm_2fa_resend

Button that sends a new code. Optional.

sm_2fa_cancel

Button that returns to the login screen. Optional.

sm-2fa-timer

Countdown 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.

Examples

# 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")
  )
}

Log the current session out

Description

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.

Usage

logout(session = shiny::getDefaultReactiveDomain())

Arguments

session

Shiny session (managed by secure_server_local or secure_server_external).

Value

Invisibly, NULL.

Examples

## Not run: 
observeEvent(input$my_logout, logout(session))

## End(Not run)

Manage users of the local credentials database

Description

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.

Usage

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)

Arguments

dbdir

Path to the duckdb file, or an open DBIConnection.

user

The user's user_id or email.

role

For set_role(), the new role. For list_users(), NULL (all users) or a role to filter by (case-insensitive).

password

The new plain-text password.

revoke

Whether set_password() closes the user's open sessions.

except

Session tokens to keep open when revoking.

name

The new display name, or NULL/NA/"" to remove it.

pushover_user_key

The user's Pushover user key, or NULL to disable 2FA.

Details

  • 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.

Value

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.

Examples

## 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)

Revoke the sessions of a user

Description

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.

Usage

revoke_sessions(user_id, except = NULL)

Arguments

user_id

The user whose sessions are revoked: the user_id of the local variant (see get_user), or the user (usually the email) stored in the session for the external variant.

except

Token(s) to keep, typically current_token() so the session making the change stays open.

Value

The number of sessions revoked.

Examples

## Not run: 
# in the server, after the user changed their password:
revoke_sessions(auth$user_id, except = current_token())

## End(Not run)

Update a user's authentication settings

Description

Change the per-user two-factor and device-remember settings of an existing user, in place. Server-only; never used in webR.

Usage

set_user_settings(
  dbdir,
  user,
  twofa_enabled = NULL,
  device_ttl_hours = NULL,
  email = NULL
)

Arguments

dbdir

Path to the duckdb file, or an open DBIConnection.

user

The user's user_id or email (case-insensitive), as in the rest of the user-management API (manage-users).

twofa_enabled

NULL leaves the flag unchanged; TRUE/ FALSE sets whether the user must complete the 2FA step.

device_ttl_hours

NULL leaves the value unchanged; a number sets the per-user device-token lifetime (hours); NA clears the override so the server's device_ttl_hours applies again.

email

Deprecated alias of user, kept so calls written for authlas < 0.7 (set_user_settings(db, email = ...)) keep working.

Value

Invisibly, the user_id. Stops with an error if the user does not exist.


Use shinymanager labels

Description

See all labels registered with get_labels(), then set custom text with set_labels().

Usage

use_language(lan = "en")

Arguments

lan

Language to use for labels, supported values are : "en", "fr", "pt-BR", "es", "de", "pl", "ja", "el", "id", "zh-CN", "no".

Value

A language object

Examples

use_language(lan = "fr")

Welcome panel for the webR access gate

Description

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.

Usage

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
)

Arguments

...

Static content to display between the logo and the button. Any 'muiMaterial' component or htmltools/shiny tag is accepted, so the screen can be freely customized.

Optional logo. Either a URL/path (character, rendered as an <img>) or a tag built by the caller.

button_label

Text of the access button.

button_id

Shiny input id the button writes to. Must match the external_input passed to secure_server_external.

identity

Named list pushed as the external identity when the button is clicked (e.g. list(user = "guest", name = "Invitado")). Use NULL to push an empty object.

button_props

Named list of extra props forwarded to the 'muiMaterial' Button (e.g. variant, size, color).

max_width

Maximum width (px) of the centered content column.

Value

A shiny.tag suitable as the waiting_ui argument of secure_app_external.

See Also

secure_app_external. A runnable example app: system.file("examples", "welcome_webr.R", package = "authlas").

Examples

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)
}