Skip to content

Commit

Permalink
fix: Adds server layer to auth_layers
Browse files Browse the repository at this point in the history
  • Loading branch information
andyquinterom committed Sep 2, 2024
1 parent d958463 commit 83ac57b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 21 deletions.
15 changes: 15 additions & 0 deletions R/auth0.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,20 @@ internal_add_auth_layers.auth0_config <- function(config, tower) {
# token and therefore we can return NULL, which will cause the
# app handler to be called.
return(NULL)
}) |>
tower::add_server_layer(function(input, output, session) {
cookies <- parse_cookies(session$request$HTTP_COOKIE)

if (is.null(cookies$access_token)) {
stop("No access token")
}

token <- access_token(config, remove_bearer(cookies$access_token))

if (is_expired(token)) {
stop("Token expired")
}

session$userData$token <- token
})
}
15 changes: 15 additions & 0 deletions R/entra_id.R
Original file line number Diff line number Diff line change
Expand Up @@ -264,5 +264,20 @@ internal_add_auth_layers.entra_id_config <- function(config, tower) {
# token and therefore we can return NULL, which will cause the
# app handler to be called.
return(NULL)
}) |>
tower::add_server_layer(function(input, output, session) {
cookies <- parse_cookies(session$request$HTTP_COOKIE)

if (is.null(cookies$access_token)) {
stop("No access token")
}

token <- access_token(config, remove_bearer(cookies$access_token))

if (is_expired(token)) {
stop("Token expired")
}

session$userData$token <- token
})
}
15 changes: 15 additions & 0 deletions R/google.R
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,20 @@ internal_add_auth_layers.google_config <- function(config, tower) {
# token and therefore we can return NULL, which will cause the
# app handler to be called.
return(NULL)
}) |>
tower::add_server_layer(function(input, output, session) {
cookies <- parse_cookies(session$request$HTTP_COOKIE)

if (is.null(cookies$access_token)) {
stop("No access token")
}

token <- access_token(config, remove_bearer(cookies$access_token))

if (is_expired(token)) {
stop("Token expired")
}

session$userData$token <- token
})
}
21 changes: 0 additions & 21 deletions R/shiny.R
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
#' @keywords internal
rsso_server <- function(config, server_func) {
function(input, output, session) {
cookies <- parse_cookies(session$request$HTTP_COOKIE)

if (is.null(cookies$access_token)) {
stop("No access token")
}

token <- access_token(config, remove_bearer(cookies$access_token))

if (is_expired(token)) {
stop("Token expired")
}

session$userData$token <- token

server_func(input, output, session)
}
}

internal_add_auth_layers <- function(config, tower) {
UseMethod("internal_add_auth_layers")
}
Expand Down

0 comments on commit 83ac57b

Please sign in to comment.