Summary
As an API-wrapping package developer, in order to reuse authentication, I would like to define authorization independent of a request.
Propose signature
auth_prepare(auth_fn, ...)
Also export a version of this corresponding to req_auth_api_key():
auth_api_key(
parameter_name,
...,
api_key = NULL,
location = c("header", "query", "cookie"),
call = rlang::caller_env()
)
Arguments
auth_fn (function) A function to use to authenticate a request.
... (any) Arguments to pass to auth_fn.
Value
Returns a list with class nectar_auth, with elements auth_fn and auth_args.
Behavior
This function is really just a nectar_auth constructor. The function itself will be very simple, but it has a number of downstream effects.
Details
I've never liked the auth_fn + auth_args pattern in req_prepare(). Instead, update req_prepare (in R/req_prepare.R) to take auth as an argument (instead of auth_fn + auth_args). Also add auth_api_key() in R/req_auth_api_key.R, which calls auth_prepare() with auth_fn = req_auth_api_key and the arguments passed into auth_api_key(). Then update vignettes/nectar.Rmd to show this updated pattern (instead of auth_fn + auth_args. We'll also need to update parameter definitions in R/aaa-shared_params.R (since auth_args won't be used anymore), and make sure any examples that reference the old pattern are updated.
This will be a breaking change, but that is ok since this will be implemented before the initial CRAN release.
Note: Do not change tidy_fn + tidy_args in req_prepare() as part of this fix, but we'll definitely use lessons learned here to inform future work to do the same for that pair of arguments.
Summary
Propose signature
Also export a version of this corresponding to
req_auth_api_key():Arguments
auth_fn(function) A function to use to authenticate a request....(any) Arguments to pass toauth_fn.Value
Returns a list with class
nectar_auth, with elementsauth_fnandauth_args.Behavior
This function is really just a
nectar_authconstructor. The function itself will be very simple, but it has a number of downstream effects.Details
I've never liked the
auth_fn+auth_argspattern inreq_prepare(). Instead, updatereq_prepare(inR/req_prepare.R) to takeauthas an argument (instead ofauth_fn+auth_args). Also addauth_api_key()inR/req_auth_api_key.R, which callsauth_prepare()withauth_fn = req_auth_api_keyand the arguments passed intoauth_api_key(). Then updatevignettes/nectar.Rmdto show this updated pattern (instead ofauth_fn+auth_args. We'll also need to update parameter definitions inR/aaa-shared_params.R(sinceauth_argswon't be used anymore), and make sure any examples that reference the old pattern are updated.This will be a breaking change, but that is ok since this will be implemented before the initial CRAN release.
Note: Do not change
tidy_fn+tidy_argsinreq_prepare()as part of this fix, but we'll definitely use lessons learned here to inform future work to do the same for that pair of arguments.