create_sql_db: Create credentials SQL database

View source: R/credentials-db-sql.R

create_sql_dbR Documentation

Create credentials SQL database

Description

Create a SQL (not SQLite but Postgres, MSSQL, MySQL...) database with credentials data using DBI interface.

Usage

create_sql_db(credentials_data, config_path)

Arguments

credentials_data

A data.frame with information about users, user and password are required.

config_path

Path to the yaml configuration. You can find a template for Posgres in package system.file("sql_config/pg_template.yml", package = "shinymanager")

Details

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

See Also

create_db, create_sql_db, check_credentials

Examples

## Not run: 

library(shiny)
library(shinymanager)

#### init the SQL Database
# first edit the .yml configuration file
system.file("sql_config/pg_template.yml", package = "shinymanager")


# Init Credentials data
credentials <- data.frame(
  user = c("shiny", "shinymanager"),
  password = c("azerty", "12345"), # password will automatically be hashed
  stringsAsFactors = FALSE
)

# Create SQL database
create_sql_db(
  credentials_data = credentials,
  config_path = "path/to/your_sql_configuration.yml"
)

### Use in shiny
ui <- fluidPage(
  tags$h2("My secure application"),
  verbatimTextOutput("auth_output")
)

# Wrap your UI with secure_app
ui <- secure_app(ui, choose_language = TRUE)


server <- function(input, output, session) {
 
 # call the server part
 # check_credentials returns a function to authenticate users
 res_auth <- secure_server(
   check_credentials = check_credentials(db = "path/to/your_sql_configuration.yml")
 )
 
 output$auth_output <- renderPrint({
   reactiveValuesToList(res_auth)
 })
 
 observe({
   print(input$shinymanager_where)
   print(input$shinymanager_language)
 })
 
 # your classic server logic
 
}

shinyApp(ui, server)


## End(Not run)


datastorm-open/shinymanager documentation built on April 28, 2024, 9:21 p.m.