This class encapsulates the logic of the
Basic authentication scheme.
See guard_basic() for more information.
Super class
fireproof::Guard -> GuardBasic
Methods
Inherited methods
Method new()
Constructor for the class
Usage
GuardBasic$new(validate, user_info = NULL, realm = "private", name = NULL)Arguments
validateA function that will be called with the arguments
username,password,realm,request, andresponseand returnsTRUEif the user is valid, andFALSEotherwise. If the function returns a character vector it is considered to be authenticated and the return value will be understood as scopes the user is granted.user_infoA function to extract user information from the username. It is called with a single argument:
userwhich is the username used for the successful authentication. The function should return a new user_info list.realmThe realm this authentication corresponds to. Will be returned to the client on a failed authentication attempt to inform them of the credentials required, though most often these days it is kept from the user.
nameThe name of the authentication
Method check_request()
A function that validates an incoming request, returning
TRUE if it is valid and FALSE if not. It decodes the credentials in
the Authorization header, splits it into username and password and then
calls the validate function provided at construction.
Method reject_response()
Upon rejection this scheme sets the response status to 401
and sets the WWW-Authenticate header to
Basic realm="<realm>", charset=UTF-8
Examples
# Create a guard of dubious quality
basic <- GuardBasic$new(
validate = function(user, password) {
user == "thomas" && password == "pedersen"
},
user_info = function(user) {
new_user_info(
name_given = "Thomas",
name_middle = "Lin",
name_family = "Pedersen"
)
}
)