curso-r / auth0

Authentication in shinyapps using Auth0 service
https://curso-r.github.io/auth0/
Other
154 stars 21 forks source link

`auth_info` null on shinyapps #72

Open chintanp opened 4 years ago

chintanp commented 4 years ago

Authentication works fine, but when I try to use the value of session$userData$auth_info, it is NULL.

 observeEvent(input$submitButton, {
    # ulid_submit <- ulid::ULIDgenerate()
    dt_submit <- Sys.time()
    auth0_sub <- session$userData$auth0_info$sub
    auth0_userid <-
      strsplit(auth0_sub, "|", fixed = TRUE)[[1]][2]
    user_name <- session$userData$auth0_info$name
    user_email <- session$userData$auth0_info$email
...

This works locally. Is it possible that shinyapps has a different version of auth0 package or underlying API that makes the session$userData NULL.

jtrecenti commented 4 years ago

Hi @chintanp, thanks for the issue.

My apps run with userinfo locally and in shinyapps.io, using the same configuration.

Working example (try to login with google): https://jubs.shinyapps.io/userinfo

Are you using app.R or ui.R/server.R paradigm?

chintanp commented 4 years ago

@jtrecenti I am using app.R. Is the code for your example app public somewhere?

jtrecenti commented 4 years ago

It's the example from the documentation. I've just added a logoutButton() and added https://jubs.shinyapps.io/userinfo to the remote_url: parameter in the .yml file.

https://curso-r.github.io/auth0/articles/examples/userinfo.html

chintanp commented 4 years ago

@jtrecenti Thanks. So it seems that the way to get to auth_info is to call it in a reactive context, which I think I am doing.

My _auth0.yml file, in case I messed something up here:

name: myApp
remote_url: https://cp84.shinyapps.io/evi_des/
shiny_config: http://localhost:8100
auth0_config:
  scope: "openid email profile"
  api_url: !expr paste0('https://', Sys.getenv('AUTH0_USER'), '.auth0.com')
  credentials:
    key: !expr Sys.getenv("AUTH0_KEY")
    secret: !expr Sys.getenv("AUTH0_SECRET")
mxfeinberg commented 3 years ago

@jtrecenti I'm able to reproduce the error explained here when I split the App.R file into ui.R and server.R files. Please look at the following example.

ui.R

auth0::auth0_ui(
  ui <- shiny::fluidPage(
    shiny::verbatimTextOutput("user_info")
  )
)

server.R

auth0::auth0_server(
  server <- function(input, output, session) {
    # print user info
    output$user_info <- shiny::renderPrint({
      session$userData$auth0_info
    })

  }
)

Am I doing something wrong? Or should I just keep everything in one file? For reference, I'm using the _auth0.yml form you are using.

homer3018 commented 1 year ago

Hello. I'm also experiencing this, even locally. I do use a server.R/ui.R paradigm. One other thing is that I'm not sure I understand correctly how one should use the remote_url and shiny_config variables. At the moment I do not use shiny_config within my _auth0.yml.

Edit : scratch that. Made a mistake and it's working now.