Skip to content

Commit

Permalink
allowing auth0_disable when using auth0_ui/auth0_server
Browse files Browse the repository at this point in the history
  • Loading branch information
williamorim committed Feb 15, 2024
1 parent 2850668 commit 7722eba
Showing 1 changed file with 49 additions and 39 deletions.
88 changes: 49 additions & 39 deletions R/shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,46 +32,51 @@
#' }
#' @export
auth0_ui <- function(ui, info) {
if (missing(info)) info <- auth0_info()
function(req) {
verify <- has_auth_code(shiny::parseQueryString(req$QUERY_STRING), info$state)
if (!verify) {
if (grepl("error=unauthorized", req$QUERY_STRING)) {
redirect <- sprintf("location.replace(\"%s\");", logout_url())
shiny::tags$script(shiny::HTML(redirect))
} else {
disable <- getOption("auth0_disable")
if (!is.null(disable) && disable) {
ui
} else {
if (missing(info)) info <- auth0_info()
function(req) {
verify <- has_auth_code(shiny::parseQueryString(req$QUERY_STRING), info$state)
if (!verify) {
if (grepl("error=unauthorized", req$QUERY_STRING)) {
redirect <- sprintf("location.replace(\"%s\");", logout_url())
shiny::tags$script(shiny::HTML(redirect))
} else {

params <- shiny::parseQueryString(req$QUERY_STRING)
params$code <- NULL
params$state <- NULL
params <- shiny::parseQueryString(req$QUERY_STRING)
params$code <- NULL
params$state <- NULL

query <- paste0("/?", paste(
mapply(paste, names(params), params, MoreArgs = list(sep = "=")),
collapse = "&"))
if (!is.null(info$remote_url) && info$remote_url != "" && !getOption("auth0_local")) {
redirect_uri <- info$remote_url
} else {
if (grepl("127.0.0.1", req$HTTP_HOST)) {
redirect_uri <- paste0("http://", gsub("127.0.0.1", "localhost", req$HTTP_HOST, query))
query <- paste0("/?", paste(
mapply(paste, names(params), params, MoreArgs = list(sep = "=")),
collapse = "&"))
if (!is.null(info$remote_url) && info$remote_url != "" && !getOption("auth0_local")) {
redirect_uri <- info$remote_url
} else {
redirect_uri <- paste0("http://", req$HTTP_HOST, query)
if (grepl("127.0.0.1", req$HTTP_HOST)) {
redirect_uri <- paste0("http://", gsub("127.0.0.1", "localhost", req$HTTP_HOST, query))
} else {
redirect_uri <- paste0("http://", req$HTTP_HOST, query)
}
}
}
redirect_uri <<- redirect_uri
redirect_uri <<- redirect_uri

query_extra <- if(is.null(info$audience)) list() else list(audience=info$audience)
url <- httr::oauth2.0_authorize_url(
info$api, info$app(redirect_uri), scope = info$scope, state = info$state,
query_extra=query_extra
)
redirect <- sprintf("location.replace(\"%s\");", url)
shiny::tags$script(shiny::HTML(redirect))
}
} else {
if (is.function(ui)) {
ui(req)
query_extra <- if(is.null(info$audience)) list() else list(audience=info$audience)
url <- httr::oauth2.0_authorize_url(
info$api, info$app(redirect_uri), scope = info$scope, state = info$state,
query_extra=query_extra
)
redirect <- sprintf("location.replace(\"%s\");", url)
shiny::tags$script(shiny::HTML(redirect))
}
} else {
ui
if (is.function(ui)) {
ui(req)
} else {
ui
}
}
}
}
Expand All @@ -85,11 +90,16 @@ auth0_ui <- function(ui, info) {
#'
#' @export
auth0_server <- function(server, info) {
if (missing(info)) info <- auth0_info()
function(input, output, session) {
shiny::isolate(auth0_server_verify(session, info$app, info$api, info$state))
shiny::observeEvent(input[["._auth0logout_"]], logout())
server(input, output, session)
disable <- getOption("auth0_disable")
if (!is.null(disable) && disable) {
server
} else {
if (missing(info)) info <- auth0_info()
function(input, output, session) {
shiny::isolate(auth0_server_verify(session, info$app, info$api, info$state))
shiny::observeEvent(input[["._auth0logout_"]], logout())
server(input, output, session)
}
}
}

Expand Down

0 comments on commit 7722eba

Please sign in to comment.