The goal of tapLock is to secure your R applications with OpenID Connect and OAuth 2.0.
tapLock is an R library that provides a simple interface to integrate OpenID Connect / OAuth 2.0 authentication into you Shiny applications and Plumber APIs. tapLock uses a unique approach to effectively secure your applications without the need to write almost any code.
You can install tapLock from CRAN with:
install.packages("tapLock")
You can install the development version of tapLock from GitHub with:
# install.packages("pak")
::pak("ixpantia/tapLock") pak
library(taplock)
<- new_openid_config(
auth_config provider = "google",
client_id = Sys.getenv("CLIENT_ID"),
client_secret = Sys.getenv("CLIENT_SECRET"),
app_url = Sys.getenv("APP_URL")
)
To secure your Shiny Application you will need to add the middleware layers using tower and configure the client credentials.
Here is an example of a Shiny application that uses tapLock to secure itself:
library(shiny)
library(tapLock)
<- new_openid_config(
auth_config provider = "google",
client_id = Sys.getenv("CLIENT_ID"),
client_secret = Sys.getenv("CLIENT_SECRET"),
app_url = Sys.getenv("APP_URL")
)
<- fluidPage(
ui $h1("r.sso example"),
tagsuiOutput("profile"),
textOutput("user")
)
<- function(input, output, session) {
server
$profile <- renderUI({
output$img(src = get_token_field(token(), "picture"))
tags
})
$user <- renderText({
output<- get_token_field(token(), "given_name")
given_name <- get_token_field(token(), "family_name")
family_name <- expires_at(token())
expires_at ::glue(
glue"Hello {given_name} {family_name}!",
"Your authenticated session will expire at {expires_at}.",
.sep = " "
)|>
}) bindEvent(TRUE)
}shinyApp(ui, server) |>
::create_tower() |>
tower::add_auth_layers(auth_config) |>
tapLock::build_tower() tower
tapLock supports the following authentication providers:
If you need support for other providers, please contact us at hola@ixpantia.com. Or, if you are a developer, you can contribute to the project by adding support for additional providers.
tapLock is unique in its approach to securing Shiny applications. tapLock utilizes middlewares that intercept all incoming requests (both HTTP and WebSocket requests) and validates the authentication token. This approach allows tapLock to be lean and efficient since no expensive WebSocket connections are started until the user is authenticated. It also prevents sensitive data in the UI portion of the application from being exposed to unauthenticated users.