The goal of {auth0}
is to implement an authentication
scheme to Shiny using OAuth Apps through the freemium service Auth0.
To create your authenticated shiny app, you need to follow the steps
below. The full decription can be found in the README
of
the package site.
http://localhost:8080
to the “Allowed Callback
URLs”, “Allowed Web Origins” and “Allowed Logout URLs”.
http://localhost:8080
to another
port.fooBar
) in “Allowed Web Origins”.Now, let’s go to R!
_auth0.yml
fileauth0::use_auth0()
:::use_auth0() auth0
You can set the directory where this file will be created using the
path=
parameter. See ?auth0::use_auth0
for
details. Your _auth0.yml
file should be like this:
name: myApp
auth0_config:
api_url: !expr paste0('https://', Sys.getenv("AUTH0_USER"), '.auth0.com')
credentials:
key: !expr Sys.getenv("AUTH0_KEY")
secret: !expr Sys.getenv("AUTH0_SECRET")
Run usethis::edit_r_environ()
and add these three
environment variables:
AUTH0_USER=johndoe
AUTH0_KEY=5wugt0W...
AUTH0_SECRET=rcaJ0p8...
There’s how you identify each of them (see the image
below):AUTH0_USER
is your username, which can be found on
the top corner of the site. AUTH0_KEY
is your Client ID,
which can be copied from inside the app page. AUTH0_SECRET
is your Client Secret, which can be copied from the app page.
You can find more information about environment variables here.
You can also fill these information directly in the
_auth0.yml
file (see below). If you do so, don’t forget to
save the _auth0.yml
file after editing it.
Write a simple shiny app in a app.R
file, like this:
library(shiny)
<- fluidPage(
ui fluidRow(plotOutput("plot"))
)
<- function(input, output, session) {
server $plot <- renderPlot({
outputplot(1:10)
})
}
# note that here we're using a different version of shinyApp!
::shinyAppAuth0(ui, server) auth0
Note: If you want to use a different path to the
auth0
configuration file, you can either pass it to
shinyAppAuth0()
or set the auth0_config_file
option by running
options(auth0_config_file = "path/to/file")
.
You can try your app running
options(shiny.port = 8080)
::runApp("app/directory/") shiny
If everything is OK, you should be forwarded to a login page and, after logging in or signing up, you’ll be redirected to your app.