| guard_key | R Documentation |
This guard is based on a mutually shared secret between the server and the client. The client provides the secret either as a header or in a cookie, and the server verifies the authenticity of the secret. Like with basic authentication, this scheme relies on additional technology like HTTPS/SSL to make it secure since the secret can otherwise easily be extracted from the request by man-in-the-middle attack.
guard_key(
key_name,
validate,
user_info = NULL,
cookie = TRUE,
name = "KeyAuth"
)
key_name |
The name of the header or cookie to store the secret under |
validate |
Either a single string with the secret
or a function that will be called with the arguments |
user_info |
A function to extract user information from the
key. It is called with a single argument: |
cookie |
Boolean. Should the secret be transmitted as a cookie. If
|
name |
The name of the guard |
This authentication is not a classic HTTP authentication scheme and thus
doesn't return a 401 response with a WWW-Authenticate header. Instead it
returns a 400 response unless another guard has already set the
response status to something else.
A GuardKey object
guard_key() automatically adds user information after
authentication. By default it will set the provider field to "local".
Further, it will set the scopes field to any scopes returned by the
validate function (provided validate is passed a function).
Since key-based authentication is seldom used with user specific keys it is unlikely that it makes sense to populate the information any further.
# Create a guard of dubious quality
key <- guard_key(
key_name = "my-key-location",
validate = "SHHH!!DONT_TELL_ANYONE"
)
# Add it to a fireproof plugin
fp <- Fireproof$new()
fp$add_guard(key, "key_auth")
# Use it in an endpoint
fp$add_auth("get", "/*", key_auth)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.