Title: | Authentication in Shiny with Auth0 |
---|---|
Description: | Uses Auth0 API (see <https://auth0.com> for more information) to use a simple authentication system. It provides tools to log in and out a shiny application using social networks or a list of e-mails. |
Authors: | Julio Trecenti [cre], Daniel Falbel [aut], José Jesus [ctb], Dean Attali [ctb], C Lente [ctb] |
Maintainer: | Julio Trecenti <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.3 |
Built: | 2024-11-11 03:59:19 UTC |
Source: | https://github.com/curso-r/auth0 |
_auth0.yml
file.Validates and creates a list of useful information from
the _auth0.yml
file.
auth0_config(config_file)
auth0_config(config_file)
config_file |
path to the |
List containing all the information from the _auth0.yml
file.
Tries to find the path to the _auth0.yml
file. First, it tries to get
this info from options(auth0_config_file = )
. If this option is NULL
(the default) it tries to find the _auth0.yml
within the working
directory. If the file does not exist, it raises an error.
auth0_find_config_file()
auth0_find_config_file()
Character vector of length one contaning the path of the
_auth0.yml
file.
Creates a list containing all the important information to connect to Auth0 service's API.
auth0_info(config)
auth0_info(config)
config |
path to the |
A list contaning scope, state, keys, OAuth2.0 app, endpoints,
audience and
remote URL. For compatibility reasons, remote_url
can be either a parameter
in the root yaml or inside a shiny_config
parameter.
use_auth0 to create an _auth0.yml
template.
auth0_logout_url()
is defunct as of auth0 0.1.2 in order to simplifly the
user experience with the logoutButton()
function.
auth0_logout_url(config_file = NULL, redirect_js = TRUE)
auth0_logout_url(config_file = NULL, redirect_js = TRUE)
config_file |
Path to YAML configuration file. |
redirect_js |
include javascript code to redirect page? Defaults to |
# simple UI with action button # AFTER auth0 0.1.2 if (interactive()) { library(shiny) library(auth0) ui <- fluidPage(logoutButton()) server <- function(input, output, session) {} config_file <- system.file("simple/_auth0.yml", package = "auth0") shinyAppAuth0(ui, server, config_file) # simple UI with action button # BEFORE auth0 0.1.2 library(shiny) library(auth0) library(shinyjs) # note that you must include shinyjs::useShinyjs() for this to work ui <- fluidPage(shinyjs::useShinyjs(), actionButton("logout_auth0", "Logout")) # server with one observer that logouts server <- function(input, output, session) { observeEvent(input$logout_auth0, { # javascript code redirecting to correct url js <- auth0_logout_url() shinyjs::runjs(js) }) } shinyAuth0App(ui, server, config_file) }
# simple UI with action button # AFTER auth0 0.1.2 if (interactive()) { library(shiny) library(auth0) ui <- fluidPage(logoutButton()) server <- function(input, output, session) {} config_file <- system.file("simple/_auth0.yml", package = "auth0") shinyAppAuth0(ui, server, config_file) # simple UI with action button # BEFORE auth0 0.1.2 library(shiny) library(auth0) library(shinyjs) # note that you must include shinyjs::useShinyjs() for this to work ui <- fluidPage(shinyjs::useShinyjs(), actionButton("logout_auth0", "Logout")) # server with one observer that logouts server <- function(input, output, session) { observeEvent(input$logout_auth0, { # javascript code redirecting to correct url js <- auth0_logout_url() shinyjs::runjs(js) }) } shinyAuth0App(ui, server, config_file) }
Log the current user out of an auth0 shiny app.
logout()
logout()
You can also use a diferent configuration file by setting the
auth0_config_file
option with:
options(auth0_config_file = "path/to/file.yaml")
.
Generate a URL that will log the user out of the app if visited.
logout_url()
logout_url()
You can also use a diferent configuration file by setting the
auth0_config_file
option with:
options(auth0_config_file = "path/to/file.yaml")
.
URL string to log out.
A logoutButton
is an actionButton
that is meant
to be used to log out of an auth0 Shiny app.
logoutButton(label = "Log out", ..., id = "._auth0logout_")
logoutButton(label = "Log out", ..., id = "._auth0logout_")
label |
The label on the button. |
... |
Named attributes to apply to the button. |
id |
An ID for the button. If you only have one logout button in
your app, you do not need to explicitly provide an ID. If you have more than
one logout button, you need to provide a unique ID to each button. When you
create a button with a non-default ID, you must create an observer that
listens to a click on this button and logs out of the app with a call to
|
if (interactive()) { ui <- fluidPage( logoutButton(), logoutButton(label = "Another logout button", id = "logout2") ) server <- function(input, output, session) { observeEvent(input$logout2, { logout() }) } shinyAuth0App(ui, server) }
if (interactive()) { ui <- fluidPage( logoutButton(), logoutButton(label = "Another logout button", id = "logout2") ) server <- function(input, output, session) { observeEvent(input$logout2, { logout() }) } shinyAuth0App(ui, server) }
This function modifies ui and server objects to run using Auth0 authentication.
shinyAppAuth0(ui, server, config_file = NULL, ...)
shinyAppAuth0(ui, server, config_file = NULL, ...)
ui |
an ordinary UI object to create shiny apps. |
server |
an ordinary server object to create shiny apps. |
config_file |
path to YAML configuration file. |
... |
Other arguments passed on to |
You can also use a diferent configuration file by setting the
auth0_config_file
option with:
options(auth0_config_file = "path/to/file.yaml")
.
Sometimes, using auth0 to develop and test apps can be frustrating,
because every time the app is started, auth0 requires the user to log-in.
To avoid this problem, one can run options(auth0_disable = TRUE)
to
disable auth0 temporarily.
As of auth0 0.1.2, shinAuth0App()
has
been renamed to shinyAppAuth0()
for consistency.
shinyAuth0App(ui, server, config_file = NULL)
shinyAuth0App(ui, server, config_file = NULL)
ui |
an ordinary UI object to create shiny apps. |
server |
an ordinary server object to create shiny apps. |
config_file |
path to YAML configuration file. |
These functions can be used in a ui.R/server.R framework, modifying the shiny objects to authenticate using Auth0 service with no pain.
auth0_ui(ui, info) auth0_server(server, info)
auth0_ui(ui, info) auth0_server(server, info)
ui |
|
info |
object returned from auth0_info. If not informed,
will try to find the |
server |
the shiny server function. |
# first, create the yml file using use_auth0() function if (interactive()) { # ui.R file library(shiny) library(auth0) auth0_ui(fluidPage(logoutButton())) # server.R file library(auth0) auth0_server(function(input, output, session) {}) # console options(shiny.port = 8080) shiny::runApp() }
# first, create the yml file using use_auth0() function if (interactive()) { # ui.R file library(shiny) library(auth0) auth0_ui(fluidPage(logoutButton())) # server.R file library(auth0) auth0_server(function(input, output, session) {}) # console options(shiny.port = 8080) shiny::runApp() }
Create an YAML containing information to connect with Auth0.
use_auth0(path = ".", file = "_auth0.yml", overwrite = FALSE)
use_auth0(path = ".", file = "_auth0.yml", overwrite = FALSE)
path |
Directory name. Should be the root of the shiny app you want to add this functionality |
file |
File name. Defaults to |
overwrite |
Will only overwrite existing path if |
The YAML configuration file has required parameters and extra parameters.
The required parameters are:
auth0_config
is a list contaning at least:
api_url
: Your account at Auth0 (e.g. https://jonhdoe.auth0.com).
It is the "Domain" in Auth0 application settings.
credentials
: Your credentials to access Auth0 API, including
key
: the Client ID in Auth0 application settings.
secret
: the Client Secret in Auth0 application settings.
The extra parameters are:
remote_url
: If you are using Shiny-Server or ShinyApps IO service.
scope
: The information that Auth0 app will access.
Defaults to "openid profile".
request
: Endpoit to request a token. Defaults to "oauth/token"
access
: Endpoit to access. Defaults to "oauth/token"