PaulC91 / shinyauthr

R package with shiny authentication modules
https://paulc91.github.io/shinyauthr/
Other
428 stars 81 forks source link

I have to re-enter my passwords when I login/logout with a google account with googleAuthR package #2

Closed nali-raz closed 6 years ago

nali-raz commented 6 years ago

Hello,

Thanks for this package. It helps me a lot.

However, as said in the title, I always have to enter my passwords when using said package (I guess this will always happen when I'll open a shiny UI for login in).

Maybe there's some workaround, but I can't find it myself.

Maybe you know how to do that.

Thanks in advance.

PaulC91 commented 6 years ago

Hi Naly, could you provide a reproducible example of how you are using this package with googleAuthR?

There is no password caching in shinyauthr so you will always have to provide your credentials each time the app is launched.

One workaround would be to use a password manager like Dashlane and save your credentials for the app using shinyauthr. It should then automatically log you in whenever you visit the URL the app is hosted on.

nali-raz commented 6 years ago

Hello Paul,

Thanks for your answer.

I think what I said was not clear.

Actually, the issues is that I have to re-enter the shinyauthr login/password during the same session.

You can see in the screenshot what's happening during the same session :

Step 1 : Login Page screen shot 2018-11-28 at 13 54 52

Step 2 : After Login via shinyauthr Succesfully logged in screen shot 2018-11-28 at 13 57 04

Step 3 : After login with my google account (via googleAuthR) shinyauthr asks me to enter my id and password again screen shot 2018-11-28 at 13 58 27

Here's a reproducible example (you just have to add the google console infos)

llibrary(shiny)
library(shinyauthr)
library(shinyjs)
library(googleAuthR)

# set google console infos
options("googleAuthR.webapp.client_id" = "xxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com")
options("googleAuthR.webapp.client_secret" = "xxxxxxxxxxxxxxxxxx")

options(shiny.port = 4441)

# dataframe that holds usernames, passwords and other user data
user_base <- data.frame(
  user = c("user1", "user2"),
  password = c("pass1", "pass2"), 
  permissions = c("admin", "standard"),
  name = c("User One", "User Two"),
  stringsAsFactors = FALSE
)

ui <- fluidPage(
  # must turn shinyjs on
  shinyjs::useShinyjs(),
  # add logout button UI 
  div(class = "pull-right", shinyauthr::logoutUI(id = "logout")),
  # add login panel UI function
  shinyauthr::loginUI(id = "login"),
  # setup table output to show user info after login
  conditionalPanel(
    condition = "output.authOK == 'TRUE'",

    tableOutput("user_table"),

    googleAuthUI("login")
  )

)

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

  # call the logout module with reactive trigger to hide/show
  logout_init <- callModule(shinyauthr::logout, 
                            id = "logout", 
                            active = reactive(credentials()$user_auth))

  # call login module supplying data frame, user and password cols
  # and reactive trigger
  credentials <- callModule(shinyauthr::login, 
                            id = "login", 
                            data = user_base,
                            user_col = user,
                            pwd_col = password,
                            log_out = reactive(logout_init()))

  # pulls out the user information returned from login module
  user_data <- reactive({credentials()$info})

  output$user_table <- renderTable({
    # use req to only render results when credentials()$user_auth is TRUE
    req(credentials()$user_auth)
    user_data()
  })

  output$authOK <- renderText({
    credentials()$user_auth
  })

  outputOptions(output, "authOK", suspendWhenHidden = FALSE)

  user <- shiny::callModule(googleAuth, "login")
}

shinyApp(ui = ui, server = server)

Thanks again.

EDIT : I think that, as the googleAuthUI function sends me in another page (external to the shiny app), the user_auth value is reset to FALSE.

PaulC91 commented 6 years ago

Hi Naly, yes it looks like the googleAuthR login is resetting the user_auth value.

Is there a reason you need both a shinyauthr login as well as a googleAuthR one?

nali-raz commented 6 years ago

That's right, I need both of them (actually, maybe I'll need another login, too : facebook for example). The shinyauthrone will be for the whole app, the other ones will be used inside it to extract some data from those sources.

nali-raz commented 6 years ago

I think I've found a solution : instead of using googleAuthUI, I'll use googleAuth_jsUI(...), from the same package, so the google authentication will be done from a popup JS menu (so I won't be redirected at an external page).

PaulC91 commented 6 years ago

OK give that a go and let me know how it goes.

If the shinyauthr login isn't being used for any server-side processes, just simply to limit access to the app, I would suggest switching to something like Nginx authentication with shiny server: https://www.r-bloggers.com/add-authentication-to-shiny-server-with-nginx/

nali-raz commented 6 years ago

Hello @PaulC91 ,

Thanks for your reply.

Nginx seems to be a good idea.

Thanks a lot.