httr2
httr2 copied to clipboard
use rstudioapi instead of readline if calling oauth_flow_auth_code() from RStudio IDE
Closes #406
Test plan
Running oauth_flow_auth_code_read("state")
successfully prompts twice (initial prompt, then state) in either case described in parent issue:
- sequential R chunks run in .Rmd
- knitting .Rmd
Implementation considerations
- Initially implemented a version of using only
askpass
, given broader generalizability outside of RStudio IDE; however, this doesn't scale as well off the shelf to the non-interactive use case (e.g., knitting in RStudio) - per?askpass::askpass
:
By default askpass() returns NULL in non-interactive sessions. (These include knitr runs and testthat tests.) If you want to force a password prompt in non-interactive sessions, set the rlib_interactive option to TRUE:
options(rlib_interactive = TRUE)
- Opted instead for an initial implementation of
rstudioapi
>askpass
, but this may be too layered - open to any feedback! - Also considered getPass but it seems less mature / robust.
Note: leaving this instance of readline() since it's not really used to solicit a character string from the user and is likely better handled by another prompt function, anyway.
In case it's relevant, gargle uses readline()
for very specific reasons, which you can read about here:
https://github.com/r-lib/gargle/pull/242
The short version is to support Jupyter notebooks and, in particular, Google Colab.
In case it's relevant, gargle uses
readline()
for very specific reasons, which you can read about here:The short version is to support Jupyter notebooks and, in particular, Google Colab.
Super relevant! I simplified a bit to only use rstudioapi
if running in RStudio IDE; otherways, stick with readline()
. Lmk if this strikes a better balance.
I do think this PR is a meaningful improvement; it would prevent folks on our end from missing an Okta re-auth prompt several times a day.
Thanks for working on this!