| GuardBearer | R Documentation |
This class encapsulates the logic of the
Bearer authentication scheme.
See guard_bearer() for more information.
fireproof::Guard -> GuardBearer
open_apiAn OpenID compliant security scheme description
new()Constructor for the class
GuardBearer$new( validate, user_info = NULL, realm = "private", allow_body_token = TRUE, allow_query_token = FALSE, name = NULL )
validateA function that will be called with the arguments
token, realm, request, and response and returns TRUE if the token
is valid, and FALSE otherwise. 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
token. It is called with a single argument: token which is the token
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.
allow_body_tokenShould it be allowed to pass the token in the request
body as a query form type with the access_token name. Defaults to TRUE
but you can turn it off to force the client to use the Authorization
header.
allow_query_tokenShould it be allowed to pass the token in the query
string of the url with the access_token name. Default to FALSE due to
severe security implications but can be turned on if you have very
well-thought-out reasons to do so.
nameThe name of the authentication
check_request()A function that validates an incoming request, returning
TRUE if it is valid and FALSE if not. It fetches the token from the
request according to the allow_body_token and allow_query_token
settings and validates it according to the provided function. If the
token is present multiple times it will fail with 400 as this is not
allowed.
GuardBearer$check_request(request, response, keys, ..., .datastore)
requestThe request to validate as a Request object
responseThe corresponding response to the request as a Response object
keysA named list of path parameters from the path matching
...Ignored
.datastoreThe data storage from firesale
reject_response()Upon rejection this scheme sets the response status to 401
and sets the WWW-Authenticate header to Bearer realm="<realm>". If
any scope is provided by the endpoint it will be appended as
, scope="<scope>" and if the token is present but invalid, it will
append , error="invalid_token"
GuardBearer$reject_response(response, scope, ..., .datastore)
responseThe response object
scopeThe scope of the endpoint
...Ignored
.datastoreThe data storage from firesale
clone()The objects of this class are cloneable with this method.
GuardBearer$clone(deep = FALSE)
deepWhether to make a deep clone.
# Create a guard of dubious quality
bearer <- GuardBearer$new(
validate = function(token) {
token == "abcd1234"
},
user_info = function(user) {
new_user_info(
name_given = "Thomas",
name_middle = "Lin",
name_family = "Pedersen"
)
}
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.