Description Usage Arguments Details Value See Also Examples
authenticate
takes one of the is_authed_*
functions of sealr (or a custom function) as input.
If the request is authenticated / authorized, authenticate
will forward the request to the next handler.
If the request is not authenticated / authorized, a 401 response will be returned to the caller.
Hence, authenticate
should only be used in plumber filters as it calls plumber::forward
.
1 | authenticate(req, res, is_authed_fun, ...)
|
req |
plumber request object |
res |
plumber response object |
is_authed_fun |
function. Function to check whether API call is authenticated / authorized. Use any of sealr's is_authed_* functions or your own custom function. See Details for requirements for custom functions. |
... |
arguments to be passed down to the is_authed_fun function. |
Custom is_authed_fun functions should return a list with the following elements:
is_authed: TRUE or FALSE. Result of the check of is_authed_fun.
status: character. short description of HTTP status code
code: integer. HTTP status code
message: character. Longer description.
You can use the helper functions is_authed_return_list
and is_authed_return_list_401
to generate those lists in your custom function.
either TRUE (invisibly from plumber::forward()) or a list containing HTTP status, HTTP status code, and a message (see details).
https://www.rplumber.io/docs/routing-and-input.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ## Not run:
pr$filter("sealr-jwt-filter", function(req, res){
sealr::authenticate(req = req, res = res, sealr::is_authed_jwt, secret = "averylongsupersecretsecret")
})
## End(Not run)
## Not run:
# define your own function somewhere
is_authed_custom <- function(req, res, a, b){
# some logic with request parameters (in req) and function parameters (a, b)
if(TRUE){ # implement this
# is authed
return(sealr::is_authed_return_list(TRUE))
} else {
# not authed :(
return(sealr::is_authed_return_list_401())
}
}
pr$filter("sealr-custom-filter", function(req, res){
sealr::authenticate(req = req, res = res, sealr::is_authed_custom, a = 5, b = 4)
})
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.