This function adds an auth guard to your API. Notably, this does
not turn on auth for any of your handlers but makes it available
for reference in an auth flow. To use it, reference it in the
auth_flow argument of functions supporting it. Guards are
defined using the various guard_*() constructors in the fireproof package.
Refer to these for further documentation
Arguments
- api
A plumber2 api object to add the authenticator to
- guard
A Guard subclass object defining an authentication scheme
- name
The name to use for referencing the guard in an authentication flow
Using annotation
To add a guard to your api defined in an annotated file use the
@authGuard tag:
The tag parameter (BasicAuth) provides the name for the guard
Examples
guard <- fireproof::guard_key(
key_name = "plumber2-key",
validate = "MY_VERY_SECRET_KEY"
)
api() |>
api_datastore(storr::driver_environment()) |>
api_auth_guard(guard, "cookie_key")
#> ── A plumber server ────────────────────────────────────────────────────────────
#> Serving on http://127.0.0.1:8080
#> Currently not running