0

From R I can retrieve status 200 when Username and Password are correct and exist using library(httr).

httr::POST(
            'https://xxx/api/Auth/Login',
            accept_json(),
            content_type_json(),
            encode = "json",
            body=list(username = Username, password = Password)

output:

Date: 2023-01-16 21:49
  Status: 200
  Content-Type: application/json; charset=utf-8
  Size: 537 B

I would like to use REST API to authenticate, not from data frame or db.

How can I use the credentials coming from the Rest API to authenticate using shinymanager?

EX:

library(shiny)
library(shinymanager)

# define credentials "I don't want this"
credentials <- data.frame(
  user = c("1"),
  password = c("1")
)

# USE THIS INSTEAD OF THE DATA.FRAME ABOVE
#  httr::POST('https://xxx/api/Auth/Login',
#    accept_json(),
#    content_type_json(),
#    encode = "json",
#    body=list(username = Username, password = Password
#  )

# Define UI
ui <- fluidPage(
  tags$h2("My secure application"),
  verbatimTextOutput("auth_output")
)
# Wrap your UI with secure_app
ui <- secure_app(ui = ui)

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

  res_auth <- secure_server(check_credentials = check_credentials(credentials))
  
  # Show user info
  output$auth_output <- renderPrint({
    reactiveValuesToList(res_auth)
  })
  
}

shinyApp(ui, server)

Thanks a lot!

DemetriusRPaula
  • 377
  • 1
  • 10
  • Please see my answer [here](https://stackoverflow.com/questions/25283736/r-shiny-rest-api-communication/71064046#71064046) on how to handle POST requests directly in shiny. – ismirsehregal Jan 17 '23 at 09:19

0 Answers0