Creates AuthBackendBasic class object.
AuthMiddleware Request Response
Other AuthBackend:
AuthBackend
,
AuthBackendBearer
,
AuthMiddleware
RestRserve::AuthBackend
-> AuthBackendBasic
# 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
#> [1] TRUE