Check credentials
check_credentials(db, passphrase = NULL)
A data.frame
with credentials data, a path to SQLite database created with create_db
or a .yaml configuration path of SQL Database created with create_sql_db
.
Passphrase to decrypt the SQLite database.
Return a function
with two arguments: user
and password
to be used in module-authentication
. The authentication function returns
a list
with 4 slots :
result : logical, result of authentication.
expired : logical, is user has expired ? Always FALSE
if db
doesn't have a expire
column.
authorized : logical, is user can access to his app ? Always TRUE
if db
doesn't have a applications
column.
user_info : the line in db
corresponding to the user.
The credentials data.frame
can have the following columns:
user (mandatory) : the user's name.
password (mandatory) : the user's password.
admin (optional) : logical, is user have admin right ? If so, user can access the admin mode (only available using a SQLite database). Initialize to FALSE if missing.
start (optional) : the date from which the user will have access to the application. Initialize to NA if missing.
expire (optional) : the date from which the user will no longer have access to the application. Initialize to NA if missing.
applications (optional) : the name of the applications to which the user is authorized,
separated by a semicolon. The name of the application corresponds to the name of the directory,
or can be declared using : options("shinymanager.application" = "my-app")
additional columns : add others columns to retrieve the values server-side after authentication
create_db
, create_sql_db
, check_credentials
# data.frame with credentials info
credentials <- data.frame(
user = c("fanny", "victor"),
password = c("azerty", "12345"),
stringsAsFactors = FALSE
)
# check a user
check_credentials(credentials)("fanny", "azerty")
#> $result
#> [1] TRUE
#>
#> $expired
#> [1] FALSE
#>
#> $authorized
#> [1] TRUE
#>
#> $user_info
#> user
#> 1 fanny
#>
check_credentials(credentials)("fanny", "azert")
#> $result
#> [1] FALSE
#>
#> $expired
#> [1] FALSE
#>
#> $authorized
#> [1] TRUE
#>
#> $user_info
#> user
#> 1 fanny
#>
check_credentials(credentials)("fannyyy", "azerty")
#> $result
#> [1] FALSE
#>
#> $expired
#> [1] FALSE
#>
#> $authorized
#> [1] FALSE
#>
#> $user_info
#> NULL
#>
# data.frame with credentials info
# using hashed password with scrypt
credentials <- data.frame(
user = c("fanny", "victor"),
password = c(scrypt::hashPassword("azerty"), scrypt::hashPassword("12345")),
is_hashed_password = TRUE,
stringsAsFactors = FALSE
)
# check a user
check_credentials(credentials)("fanny", "azerty")
#> $result
#> [1] TRUE
#>
#> $expired
#> [1] FALSE
#>
#> $authorized
#> [1] TRUE
#>
#> $user_info
#> user
#> 1 fanny
#>
check_credentials(credentials)("fanny", "azert")
#> $result
#> [1] FALSE
#>
#> $expired
#> [1] FALSE
#>
#> $authorized
#> [1] TRUE
#>
#> $user_info
#> user
#> 1 fanny
#>
check_credentials(credentials)("fannyyy", "azerty")
#> $result
#> [1] FALSE
#>
#> $expired
#> [1] FALSE
#>
#> $authorized
#> [1] FALSE
#>
#> $user_info
#> NULL
#>
if (FALSE) {
## With a SQLite database:
check_credentials("credentials.sqlite", passphrase = "supersecret")
## With a SQL database:
check_credentials("config_db.yml")
}