Package 'auth0'

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

Help Index


Parse ⁠_auth0.yml⁠ file.

Description

Validates and creates a list of useful information from the ⁠_auth0.yml⁠ file.

Usage

auth0_config(config_file)

Arguments

config_file

path to the ⁠_auth0.yml⁠ file. If not informed, will try to find the file using auth0_find_config_file.

Value

List containing all the information from the ⁠_auth0.yml⁠ file.


Find the configuration file.

Description

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.

Usage

auth0_find_config_file()

Value

Character vector of length one contaning the path of the ⁠_auth0.yml⁠ file.

See Also

use_auth0.


Information used to connect to Auth0.

Description

Creates a list containing all the important information to connect to Auth0 service's API.

Usage

auth0_info(config)

Arguments

config

path to the ⁠_auth0.yml⁠ file or the object returned by auth0_config. If not informed, will try to find the file using auth0_find_config_file.

Value

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.

See Also

use_auth0 to create an ⁠_auth0.yml⁠ template.


Generate logout URL

Description

auth0_logout_url() is defunct as of auth0 0.1.2 in order to simplifly the user experience with the logoutButton() function.

Usage

auth0_logout_url(config_file = NULL, redirect_js = TRUE)

Arguments

config_file

Path to YAML configuration file.

redirect_js

include javascript code to redirect page? Defaults to TRUE.

Examples

# 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 out of an auth0 app

Description

Log the current user out of an auth0 shiny app.

Usage

logout()

Details

You can also use a diferent configuration file by setting the auth0_config_file option with: options(auth0_config_file = "path/to/file.yaml").

See Also

logoutButton, logout_url


Generate a logout URL

Description

Generate a URL that will log the user out of the app if visited.

Usage

logout_url()

Details

You can also use a diferent configuration file by setting the auth0_config_file option with: options(auth0_config_file = "path/to/file.yaml").

Value

URL string to log out.

See Also

logoutButton, logout


Create a button to log out

Description

A logoutButton is an actionButton that is meant to be used to log out of an auth0 Shiny app.

Usage

logoutButton(label = "Log out", ..., id = "._auth0logout_")

Arguments

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 logout.

See Also

logout, logout_url

Examples

if (interactive()) {
  ui <- fluidPage(
    logoutButton(),
    logoutButton(label = "Another logout button", id = "logout2")
  )
  server <- function(input, output, session) {
    observeEvent(input$logout2, {
      logout()
    })
  }
  shinyAuth0App(ui, server)
}

Create a Shiny app object with Auth0 Authentication

Description

This function modifies ui and server objects to run using Auth0 authentication.

Usage

shinyAppAuth0(ui, server, config_file = NULL, ...)

Arguments

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 shiny::shinyApp().

Details

You can also use a diferent configuration file by setting the auth0_config_file option with: options(auth0_config_file = "path/to/file.yaml").

Disable auth0 while developing apps

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.


Create a Shiny app object with Auth0 Authentication

Description

As of auth0 0.1.2, shinAuth0App() has been renamed to shinyAppAuth0() for consistency.

Usage

shinyAuth0App(ui, server, config_file = NULL)

Arguments

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.


Modifies ui/server objects to authenticate using Auth0.

Description

These functions can be used in a ui.R/server.R framework, modifying the shiny objects to authenticate using Auth0 service with no pain.

Usage

auth0_ui(ui, info)

auth0_server(server, info)

Arguments

ui

shiny.tag.list object to generate the user interface.

info

object returned from auth0_info. If not informed, will try to find the ⁠_auth0.yml⁠ and create it automatically.

server

the shiny server function.

See Also

auth0_info.

Examples

# 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()
}

Auth0 configuration file

Description

Create an YAML containing information to connect with Auth0.

Usage

use_auth0(path = ".", file = "_auth0.yml", overwrite = FALSE)

Arguments

path

Directory name. Should be the root of the shiny app you want to add this functionality

file

File name. Defaults to ⁠_auth0.yml⁠.

overwrite

Will only overwrite existing path if TRUE.

Details

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"