OAuth2.0 with R/Shiny and Databricks
I am going to write a blog post about how to integrate RStudio workbench with Databricks using oauth2.0.
TL;DR
- Install
Databricks CLI
- Register custom application in
Databricks
- Initialize
Shiny
application - Authenticate with
Databricks
usingOAuth2.0
- Use
Databricks
API to fetch data fromDatabricks
workspace - Display data in
Shiny
application
What is Databrics
?
Databricks
is a company founded by the original creators of Apache Spark
. Databricks
grew out of the AMPlab
project at UC Berkeley
, which was involved in making Apache Spark
, an open-source distributed computing framework built atop Scala
and Apache Mesos
.
Why to authenthicate with OAuth in Databricks? In simple terms, comparing to PAT
Databricks
supports two types of authentication: OAuth 2.0
and Personal Access Token (PAT)
. OAuth 2.0
is the recommended authentication method. OAuth 2.0
is an industry-standard protocol for authorization. It enables third-party applications to obtain limited access to HTTP
services, either on behalf of a resource owner or by allowing a third-party application to obtain access on its own behalf. OAuth 2.0
is a more secure method of authentication than PAT
because it enables you to control the level of access that third-party applications have to your Databricks
resources. OAuth 2.0
also enables you to revoke access to your Databricks
resources at any time.
Pre-requisites
R/Shiny
Python
(will be used byreticulate
package)- Access to
Databricks
account + running workspace
Are you ready? Let’s go!
Install Databricks CLI - link
Register custom application in Databricks
Initialize Shiny application
library(shiny)
ui <- fluidPage(
textOutput("link"),
uiOutput("pdf")
)
server <- function(input, output, session) {
example_get_data_url <- session$registerDataObj(
name = "example-get-api",
data = list(),
filterFunc = function(data, req) {
if(req$REQUEST_METHOD == "GET") {
pdfPath = './assets/sample.pdf'
content = readBin(pdfPath, "raw", file.info(pdfPath)$size)
httpResponse(200, "application/pdf", content)
}
}
)
output$pdf <- renderUI(
tags$iframe(
src = example_get_data_url
)
)
output$link <- renderText({
paste0(
session$clientData$url_protocol,
'//',
session$clientData$url_hostname,
':',
session$clientData$url_port,
'/',
example_get_data_url
)
})
}
shinyApp(ui, server)