httr2 icon indicating copy to clipboard operation
httr2 copied to clipboard

use rstudioapi instead of readline if calling oauth_flow_auth_code() from RStudio IDE

Open fh-mthomson opened this issue 1 year ago • 3 comments

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:

  1. sequential R chunks run in .Rmd
  2. 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.

fh-mthomson avatar Dec 12 '23 01:12 fh-mthomson

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.

jennybc avatar Dec 12 '23 20:12 jennybc

In case it's relevant, gargle uses readline() for very specific reasons, which you can read about here:

r-lib/gargle#242

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.

fh-mthomson avatar Dec 21 '23 00:12 fh-mthomson

Thanks for working on this!

hadley avatar Dec 21 '23 13:12 hadley