Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger is locked when using the checkAuth filter example from docs #945

Open
alexverse opened this issue Feb 5, 2024 · 0 comments
Open

Comments

@alexverse
Copy link

alexverse commented Feb 5, 2024

Describe the bug
When using the example for authentication the Swagger page is locked. Is this intentional, and is there a recommended way to enable docs while having authentication?

To Reproduce
Run this example taken from plumber documentation

library(plumber)

#* @apiTitle Plumber Example API
#* @apiDescription Plumber example description.
#* @filter setuser
function(req) {
  un <- req$cookies$user
  # Make req$username available to endpoints
  req$username <- un
  plumber::forward()
}

#* @filter checkAuth
function(req, res) {
  if (is.null(req$username)){
    res$status <- 401 # Unauthorized
    return(list(error="Authentication required"))
  } else {
    plumber::forward()
  }
}

#* Echo back the input
#* @param msg The message to echo
#* @get /echo
function(msg = "") {
    list(msg = paste0("The message is: '", msg, "'"))
}

When I visit /__docs__/ I get an error

Expected behavior
Swagger docs are rendered

Screenshots
image

Additional context

R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Etc/UTC
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] jsonlite_1.8.7   purrr_1.0.2      rlang_1.1.1      plumber_1.2.1    conflicted_1.2.0

loaded via a namespace (and not attached):
 [1] later_1.3.1       R6_2.5.1          httpuv_1.6.11     fastmap_1.1.1     swagger_3.33.1    magrittr_2.0.3    webutils_1.2.0    cachem_1.0.8     
 [9] memoise_2.0.1     lifecycle_1.0.3   promises_1.2.1    cli_3.6.1         vctrs_0.6.5       rsconnect_1.1.0   compiler_4.3.1    rstudioapi_0.15.0
[17] tools_4.3.1       ellipsis_0.3.2    Rcpp_1.0.11       stringi_1.7.12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant