Skip to content

auth_prepare() function #81

@jonthegeek

Description

@jonthegeek

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.

Metadata

Metadata

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions