Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use auth0 R package in Golem App #327

Closed
henrique1008 opened this issue Dec 30, 2019 · 7 comments
Closed

Use auth0 R package in Golem App #327

henrique1008 opened this issue Dec 30, 2019 · 7 comments

Comments

@henrique1008
Copy link

Good morning, I'm having trouble incorporating an auth0 authentication package in Golem. It is possible ?

@ColinFay
Copy link
Member

Hey @henrique1008

A golem works just like any shiny app, so yes if it's possible in shiny it's possible in golem.

Can you share what you have tried so far?

@henrique1008
Copy link
Author

henrique1008 commented Jan 2, 2020

Good Morning

Sorry for the delay in returning.

I initially tried to change the run_app.R file.

run_app <- function(...) {
  with_golem_options(
    app = shinyAppAuth0(ui = app_ui, server = app_server), 
    golem_opts = list(...)
  )
}

seguindo as instruções do link: auth0

I will try to build a code example and upload to github in the afternoon, with the entire golem structure, including attempted authentication.

@jtrecenti
Copy link

jtrecenti commented Jan 2, 2020

Hi @henrique1008 , I use {auth0} and {golem} all the time in my apps without any problems! In my experience, I think the fastest workflow to make them work together would be

  1. Create the app normally using {golem}

  2. add a _auth0.yml inside de inst/app/, using auth0::use_auth0("inst/app") and set up the keys using usethis::edit_r_environ("project") (see the README from {auth0} for details).

  3. create a new function run_app_auth0(), which is basically run_app() but wrapped with auth0::shinyAppAuth() instead of shiny::shinyApp()

#' Run the Shiny Application
#'
#' @export
#' @importFrom golem with_golem_options
run_app_auth0 <- function(...) {
  with_golem_options(
    app = auth0::shinyAppAuth0(
      ui = app_ui(),        # these parenthesis are important
      server = app_server, 
      config_file = system.file("app/_auth0.yml", package = "<PKG_NAME>")
    ), 
    golem_opts = list(...)
  )
}
  1. Create a app.R using either golem::add_shinyserver_file() or golem::add_shinyappsio_file().

  2. Replace the call to run_app() by run_app_auth0()

  3. to test locally, don't forget to set the shiny port using options(shiny.port = 8080) or the port authorized in Auth0's site.

I think it's a good practice to keep the run_app() function to test the app locally. Other option would be substitute run_app() body by run_app_auth0() body and set options(auth0_disable = TRUE) when testing locally.

@henrique1008
Copy link
Author

henrique1008 commented Jan 2, 2020

Hi @jtrecenti , I tested, and one thing that didn't work was logout auth0::logoutButton().

I uploaded a repository on github with a test golem with what I did to deploy Auth0 authentication.

link: repositório

Auth0 authentication credentials

password: Testeauth2020
login: [email protected]

@jtrecenti
Copy link

jtrecenti commented Jan 2, 2020

It works if you set

options("golem.app.prod" = TRUE, shiny.port = 8080,
             auth0_config_file = system.file("app/_auth0.yml", package = "golem.auth0"))

I think that the actual setup it is not ideal because the path is already set inside run_app_auth0(). Anyway, this is not not an issue for golem. I created curso-r/auth0#59 in {auth0} to address this

@henrique1008
Copy link
Author

Thanks so much for the help, everything is working now.

@ColinFay
Copy link
Member

ColinFay commented Sep 6, 2020

The problem seems to be solved (thanks a lot @jtrecenti).

Closing now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants