datastorm-open / shinymanager

Simple and secure authentification mechanism for single shiny applications.
https://datastorm-open.github.io/shinymanager/
379 stars 79 forks source link

Admin mode for shiny app with shinymanager and Postgres database AND cookie based authentication #170

Closed devops-qubits closed 8 months ago

devops-qubits commented 12 months ago

First of all, thanks for making this great R package available.

I have a working Rshiny app with shinymanager using Postgres database hosted on AWS. I wonder if there is any way to make the admin mode available in this app. According to shinymanager documentation, admin mode is available only with sqlite database which has certain limitations for apps hosted on shinyapps.io

Secondly, it is possible to make cookie-based authentication with shinymanager, so that the user don't have to type credentials everytime they open the app.

Thanks for your time and support.

mubashirqasim commented 11 months ago

I have updated the shinymanager package with new functions to add admin page capability while using SQL databases like PostgreSQL.

I have added a pull request to add additional updates to the main package. In the meantime, you can install the R-Package from here:

remotes::install_github("devops-qubits/shinymanager")

You would need to add your own DB creds in the conn.

library(RPostgres)
library(shiny)
library(shinymanager)
library(DBI)

conn <- DBI::dbConnect(RPostgres::Postgres(),
                       host   = "localhost",
                       dbname = "postgres_db",
                       user = "postgres_user",
                       password = "postgres_user",
                       port = 5432)

# credentials <- data.frame(
#   user = c("shiny", "admin"),
#   password = c("shiny", "admin"),
#   start = c(NA, NA),
#   expire = c(NA, NA),
#   admin = c(FALSE, TRUE),
#   stringsAsFactors = FALSE)

## Write SQL tables
create_sql_tables(conn,
                  credentials_data = credentials,
                  passphrase = NULL
)

ui <- fluidPage(
  h2("My secure application"),
  verbatimTextOutput("auth_output")
)

ui <- secure_app(ui, enable_admin = TRUE)

server <- function(input, output, session) {

  res_auth <- secure_server(
    check_credentials = check_credentials(conn, passphrase = NULL, sql = TRUE)
  )

  output$auth_output <- renderPrint({ reactiveValuesToList(res_auth) })

}

shinyApp(ui, server)
bthieurmel commented 8 months ago

180

Available on 1.0.500

mkaranja commented 4 days ago

Where is the 'create_sql_tables' function ? It's not part of shinymanager