Auto login to remote website that's embedded in an iframe on a shiny app


#1

Can anyone help me figure out how to automatically login to an external website that's embedded in an iframe in my shiny app, and then pass in values to a javascript file? I'd like to allow users to click on a row of a datatable, and then send the id of the object in that row to an external website that will allow them to view a picture of the object.

I've found some help from the answers on this StackOverflow question for logging in using javascript: https://stackoverflow.com/questions/11878947/auto-login-remote-site-inner-in-iframe

However, I can't get it to work. Here's what I currently have:

library(shiny)
library(shinydashboard)


################
ui <- fluidPage(titlePanel("Test Login Page"),
                mainPanel(
                  tags$form(id = "login"
                            , target = "myIframe"
                            , method = "post"
                            , action = "https://LoginPage.html"
                            , tags$input(type = "hidden"
                                         , name = "username"
                                         , value = "myName@email.com")
                            , tags$input(type = "hidden"
                                         , name = "password"
                                         , value = "passw@rd")
                            , tags$input(type = "hidden"
                                         , id = "login"
                                         , value = "Submit")
                  )
                  , tags$iframe(id = "myIframe"
                                , name = "myIframe"
                                , seamless = "seamless"
                                , height = 500
                                , width = "100%"
                  )
                  , tags$script(type = "text/javascript"
                                , HTML("document.getElementById('login').submit();
                                       var iframe = document.getElementById('myIframe');
                                       iframe.onload = function() {
                                       if(iframe.src != 'https://LoggedInPage.html'){
                                          iframe.src = 'https://LoggedInPage.html';
                                       }
                                       }")
                                )
                )
)

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

}

shinyApp(ui = ui, server = server)```

What I'm hoping will happen is that when the shiny app loads, the iframe will load the username and password of the login page, and take the user directly to the logged in page. I'd appreciate any help! Thanks very much!