AuthBackendBasic {RestRserve} | R Documentation |
Basic authorization backend
Description
Creates AuthBackendBasic class object.
Super class
RestRserve::AuthBackend
-> AuthBackendBasic
Methods
Public methods
Method new()
Creates AuthBackendBasic class object.
Usage
AuthBackendBasic$new(FUN)
Arguments
FUN
Function to perform authentication which takes two arguments -
user
andpassword
. Returns boolean - whether access is allowed for a requesteduser
or not.
Method authenticate()
Provide authentication for the given request.
Usage
AuthBackendBasic$authenticate(request, response)
Arguments
Returns
Boolean - whether access is allowed for a requested user
or not.
Method clone()
The objects of this class are cloneable with this method.
Usage
AuthBackendBasic$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
References
See Also
AuthMiddleware Request Response
Other AuthBackend:
AuthBackend
,
AuthBackendBearer
,
AuthMiddleware
Examples
# 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
[Package RestRserve version 1.2.3 Index]