| AuthBackendBasic | R Documentation |
Creates AuthBackendBasic class object.
RestRserve::AuthBackend -> AuthBackendBasic
new()Creates AuthBackendBasic class object.
AuthBackendBasic$new(FUN)
FUNFunction to perform authentication which takes two arguments -
user and password. Returns boolean - whether access is allowed for
a requested user or not.
authenticate()Provide authentication for the given request.
AuthBackendBasic$authenticate(request, response)
requestRequest object.
responseResponse object.
Boolean - whether access is allowed for a requested user or not.
clone()The objects of this class are cloneable with this method.
AuthBackendBasic$clone(deep = FALSE)
deepWhether to make a deep clone.
AuthMiddleware Request Response
Other AuthBackend:
AuthBackend,
AuthBackendBearer,
AuthMiddleware
# init users database
user_db = list(
"user-1" = "password-1",
"user-2" = "password-2"
)
# define authentication handler
auth_fun = function(user, password) {
if (is.null(user_db[[user]])) return(FALSE) # not found
if (!identical(user_db[[user]], password)) return(FALSE) # incorrect
return(TRUE)
}
# init backend
auth_backend = AuthBackendBasic$new(FUN = auth_fun)
# test backend
# define credentials (see RFC)
creds = jsonlite::base64_enc("user-1:password-1")
# generate request headers
h = list("Authorization" = sprintf("Basic %s", creds))
# simulate request
rq = Request$new(path = "/", headers = h)
# init response object
rs = Response$new()
# perform authentication
auth_backend$authenticate(rq, rs) # TRUE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.