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

Error: Function askForPassword not found in RStudio when running auth_setup() outside of RStudio #158

Closed
vidonne opened this issue Oct 29, 2024 · 10 comments

Comments

@vidonne
Copy link

vidonne commented Oct 29, 2024

Description
I'm trying to authenticate with the rtoot package in VS Code on WSL Ubuntu. After loading the package and running auth_setup(), I get the following error:

Error: Function askForPassword not found in RStudio

This error seems to be due to askForPassword() being specific to RStudio, which isn’t available in my setup.

Steps to Reproduce

  1. Open R in VS Code on WSL Ubuntu.
  2. Load rtoot package: library(rtoot)
  3. Run auth_setup() to attempt authentication.

Expected Behavior
I expect to be prompted for a token or authentication details, even when not in RStudio.

Observed Behavior
The error Error: Function askForPassword not found in RStudio appears, halting the authentication process.

Session Info
To help with debugging, here is my session information:

R version 4.4.1 (2024-06-14)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.1 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.12.0 
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8        LC_COLLATE=C.UTF-8    
 [5] LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8    LC_PAPER=C.UTF-8       LC_NAME=C             
 [9] LC_ADDRESS=C           LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

time zone: Europe/Berlin
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rtoot_0.3.4

loaded via a namespace (and not attached):
[1] compiler_4.4.1 cli_3.6.3      jsonlite_1.8.9 rlang_1.1.4  

Could there be an alternative way to securely prompt for passwords outside of RStudio, perhaps using the askpass package or allowing direct environment variable input?

Thank you for your help!

@schochastics
Copy link
Member

If you are not using RStudio, try the following:

auth_setup(browser = FALSE)

Just checked on my Ubuntu machine with VS Code setup and it should work

@vidonne
Copy link
Author

vidonne commented Oct 29, 2024

Thanks for your quick reply, unfortunately still getting the same error.

auth_setup(browser = FALSE)

On which instance do you want to authenticate (e.g., "mastodon.social")? fosstodon.org
What type of token do you want? 

1: public
2: user

Selection: user

Navigate to URL PROVIDED BY auth_setup() to obtain an authorization code. Press Enter to the next step.
 
Error: Function askForPassword not found in RStudio
``

@chainsawriot
Copy link
Collaborator

rtoot/R/utils.R

Lines 231 to 236 in a0262e0

passFun <- readline
if (isTRUE(pass) && isTRUE(check_rstudio) && (requireNamespace("rstudioapi", quietly = TRUE))) {
if (rstudioapi::isAvailable()) {
passFun <- rstudioapi::askForPassword
}
}

The question now is why this chain of tests (line 232 and line 233) is TRUE on the machine. It's difficult to debug without access to your machine; could you do this:

debug(rtoot:::rtoot_ask)
auth_setup(browser = FALSE)

Step through the running of rtoot_ask and tell us when it fails. Thank you very much!

@vidonne
Copy link
Author

vidonne commented Oct 29, 2024

Thanks here is what's happening after the URL step:

debugging in: rtoot_ask("", pass = FALSE, check_rstudio = FALSE)
debug: {
    if (!is.null(options("rtoot_cheatcode")$rtoot_cheatcode)) {
        if (options("rtoot_cheatcode")$rtoot_cheatcode == "uuddlrlrba") {
            sayif(verbose, prompt)
            return(options("rtoot_cheat_ask_answer")$rtoot_cheat_ask_answer)
        }
    }
    if (isFALSE(interactive())) {
        sayif(verbose, prompt)
        return(default)
    }
    passFun <- readline
    if (isTRUE(pass) && isTRUE(check_rstudio) && (requireNamespace("rstudioapi", 
        quietly = TRUE))) {
        if (rstudioapi::isAvailable()) {
            passFun <- rstudioapi::askForPassword
        }
    }
    return(passFun(prompt = prompt))
}
Browse[1]>
debug: if (!is.null(options("rtoot_cheatcode")$rtoot_cheatcode)) {
    if (options("rtoot_cheatcode")$rtoot_cheatcode == "uuddlrlrba") {
        sayif(verbose, prompt)
        return(options("rtoot_cheat_ask_answer")$rtoot_cheat_ask_answer)
    }
}

Browse[1]>
debug: if (isFALSE(interactive())) {
    sayif(verbose, prompt)
    return(default)
}

Browse[1]>
debug: passFun <- readline

Browse[1]>
debug: if (isTRUE(pass) && isTRUE(check_rstudio) && (requireNamespace("rstudioapi", 
    quietly = TRUE))) {
    if (rstudioapi::isAvailable()) {
        passFun <- rstudioapi::askForPassword
    }
}

Browse[1]>
debug: return(passFun(prompt = prompt))

Browse[1]>

 
exiting from: rtoot_ask("", pass = FALSE, check_rstudio = FALSE)
debugging in: rtoot_ask(prompt = "enter authorization code: ", pass = TRUE, 
    check_rstudio = TRUE, default = "")
debug: {
    if (!is.null(options("rtoot_cheatcode")$rtoot_cheatcode)) {
        if (options("rtoot_cheatcode")$rtoot_cheatcode == "uuddlrlrba") {
            sayif(verbose, prompt)
            return(options("rtoot_cheat_ask_answer")$rtoot_cheat_ask_answer)
        }
    }
    if (isFALSE(interactive())) {
        sayif(verbose, prompt)
        return(default)
    }
    passFun <- readline
    if (isTRUE(pass) && isTRUE(check_rstudio) && (requireNamespace("rstudioapi", 
        quietly = TRUE))) {
        if (rstudioapi::isAvailable()) {
            passFun <- rstudioapi::askForPassword
        }
    }
    return(passFun(prompt = prompt))
}
Browse[1]>
debug: if (!is.null(options("rtoot_cheatcode")$rtoot_cheatcode)) {
    if (options("rtoot_cheatcode")$rtoot_cheatcode == "uuddlrlrba") {
        sayif(verbose, prompt)
        return(options("rtoot_cheat_ask_answer")$rtoot_cheat_ask_answer)
    }
}

Browse[1]>
debug: if (isFALSE(interactive())) {
    sayif(verbose, prompt)
    return(default)
}

Browse[1]>
debug: passFun <- readline

Browse[1]>
debug: if (isTRUE(pass) && isTRUE(check_rstudio) && (requireNamespace("rstudioapi", 
    quietly = TRUE))) {
    if (rstudioapi::isAvailable()) {
        passFun <- rstudioapi::askForPassword
    }
}

Browse[1]>
debug: if (rstudioapi::isAvailable()) {
    passFun <- rstudioapi::askForPassword
}

Browse[1]>
debug: passFun <- rstudioapi::askForPassword

Browse[1]>
debug: return(passFun(prompt = prompt))

Browse[1]>
Error: Function askForPassword not found in RStudio

Let me know if this helps. Thanks a lot for your support.

@chainsawriot
Copy link
Collaborator

@vidonne So,

rstudioapi::isAvailable()

returns TRUE on your VS Code setup ?

@vidonne
Copy link
Author

vidonne commented Oct 29, 2024

For some mystic reasons yes it does return TRUE

It seems something kind of similar raised in positron rstudio/rstudioapi#302

@chainsawriot
Copy link
Collaborator

ok, thank you for the pointer. Now I know the problem. rstudio/rstudioapi#302

Thank you Positron. I will modify this to not using rstudioapi as there is no reliable way now to really check whether the GUI password input is available.

@vidonne
Copy link
Author

vidonne commented Oct 29, 2024

Maybe this could do the trick:

rstudioapi::hasFun("askForPassword")
[1] FALSE

From one of the answer: rstudio/rstudioapi#302 (comment)

chainsawriot added a commit that referenced this issue Oct 29, 2024
@chainsawriot
Copy link
Collaborator

@vidonne Could you give this a try?

remotes::install_github("gesistsa/rtoot@fix158")

@vidonne
Copy link
Author

vidonne commented Oct 29, 2024

Worked perfectly thanks for the fix!!!

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

No branches or pull requests

3 participants