datastorm-open / shinymanager

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

How to use shinymanager with reCaptcha? #141

Open RafaelEduardoDiaz opened 2 years ago

RafaelEduardoDiaz commented 2 years ago

I'm using shinymanager in conjunction with reCaptcha V3, however I can't get it to work properly. My goal is to display the credentials of the user who logged in.

# define some credentials
credentials <- data.frame(user = "shiny", password = "1", start = "2019-04-15", expire = NA, admin = FALSE, stringsAsFactors = FALSE)

library(shiny)
library(shinymanager)
library(shinyjs)
library(shinygCAPTCHAv3)

ui <- fluidPage(
  useShinyjs(),
  GreCAPTCHAv3Ui(siteKey = "6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI","homepage","responseReceived"),
  tags$h2("My secure application"),
  verbatimTextOutput("auth_output")
)

ui <- secure_app(ui, fab_position = "bottom-left")

server <- function(input, output, session) {
  res_auth <- secure_server(check_credentials = check_credentials(credentials))
  observeEvent(input$responseReceived,{
    result <- GreCAPTCHAv3Server(secretKey = "6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe",input$responseReceived)
    if(result$success){
      output$auth_output <- renderPrint({reactiveValuesToList(res_auth)})
      }
  })
}

shinyApp(ui, server)

Expected output

image

sciordia commented 1 year ago

Hello Rafael,

Have you managed to successfully incorporate reCaptcha in Shinymanager?. I've tried to do it too but I can't get it to work properly.

I've used your code as a base but the first thing I've seen is that if you run your example the reCaptcha(v3) appears in the UI after confirming the credentials. To avoid the attack by bots, shouldn't recaptcha be loaded in the login page? After that I don't think it makes sense.

I hope you can help me.

Thank you very much for your example.