Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth functions #3

Open
9 of 13 tasks
ijlyttle opened this issue Jan 4, 2022 · 0 comments · May be fixed by #9
Open
9 of 13 tasks

auth functions #3

ijlyttle opened this issue Jan 4, 2022 · 0 comments · May be fixed by #9

Comments

@ijlyttle
Copy link
Member

ijlyttle commented Jan 4, 2022

Gotta start somewhere - looking over the httr2 Wrapping APIs article, I see code like this:

library("httr2")

request("https://api.github.com/user") %>% 
  req_oauth_auth_code(client, auth_url = "https://github.com/login/oauth/authorize") %>% 
  req_perform() %>% 
  resp_body_json()

For us, I think it could be useful to think of auth as a function you create, so we might suggest something like this:

library("httr2")
library("cardboard")

# use interactive login
req_auth <- bx_auth_create_interactive(id, secret, .test = TRUE) 

request("https://api.box.com/2.0/users/me") %>%
  req_auth() %>%
  req_perform() %>% 
  resp_body_json()

We would need a family of functions:

# if auth is:
#  - cardborad_function: no-op
#  - character: consult keyring
#  - list: parse
#  - NULL: consult keyring, return if only one candidiate
bx_auth_get(auth = NULL)

# sets default using `bx_auth_get()`
bx_auth_use(auth = NULL, quiet = FALSE) 

# returns default auth
bx_auth()
# these return auth functions
bx_auth_create_interactive(id, secret, cache_disk = FALSE, .test = TRUE)
bx_auth_create_credentials(id, secret, subject_type, subject_id, cache_disk = FALSE, .test = TRUE)
 
# returns list with elements `type`, `params`
bx_auth_serialize(auth) # can be function or character (keyring name)
bx_auth_parse(type = c("interactive", "credentials"), params) # returns auth function

# returns logical, invisibly
bx_auth_test(auth, quiet = FALSE)  # can be function or character (keyring name)

# returns NULL, invisibly
bx_auth_inspect(auth)  # can be function or character (keyring name)

also

# sets auth in package environment
bx_auth_use(auth = NULL, .test = TRUE) # can be function or character (keyring name), NULL means use only name

# if key is NULL, use internal function to generate then print to screen
bx_auth_encrypt(auth, file, key = NULL, nonce = NULL)
bx_auth_decrypt(file, key, nonce = NULL, .test = TRUE)
  • bx_auth_get()
  • bx_auth_create_interactive()
  • bx_auth_create_credentials()
  • bx_auth_test()
  • bx_auth_serialize()
  • bx_auth_parse()
  • bx_auth_inspect()
  • bx_auth_use()
  • bx_auth()
  • bx_auth_encrypt()
  • bx_auth_decrypt()

Don't forget

  • set up testing
  • document everything
@ijlyttle ijlyttle linked a pull request Jan 6, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant