r-box / boxr

:package: A high-level R interface for the box.com API
https://r-box.github.io/boxr
Other
63 stars 24 forks source link

boxr::box_auth() require authorization code #191

Closed jtraurig closed 4 years ago

jtraurig commented 4 years ago

https://r-box.github.io/boxr/articles/boxr-app-interactive.html

I have used the above instructions to attempt to authorize box use on an Rstudio server. While this works for our local serves this process does not work for RStudio servers running on AWS Virtual machines. Is there some way around a need to have to type in an authorization code with using box_auth() on Rstudio server

Capture

Capture2

nathancday commented 4 years ago

Have you seen the section about using on a remote RStudio instance? https://r-box.github.io/boxr/articles/boxr-app-interactive.html#transfer

There is also a JWT based method that doesn't require the browser confirmation, but does require a Box service account. https://r-box.github.io/boxr/articles/boxr-app-service.html

jtraurig commented 4 years ago

Yes. I have seen the section about using on remote server. I have followed the instructions. Unfortunately uploading the .box-oauth file and adding credentials to .Renviron does not work.

On Mon, Oct 5, 2020, 17:08 Nathan (Nate) Day notifications@github.com wrote:

Have you seen the section about using on a remote RStudio instance? https://r-box.github.io/boxr/articles/boxr-app-interactive.html#transfer

There is also a JWT based method that doesn't require the browser confirmation, but does require a Box service account. https://r-box.github.io/boxr/articles/boxr-app-service.html

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/r-box/boxr/issues/191#issuecomment-703889575, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANENHT55KZ56RQPRH2NIUW3SJIYTTANCNFSM4SFESZSA .

jtraurig commented 4 years ago

Update. I think I've made some progress. The "httr_oob_default" must = FALSE. That gets me passed the part where R is requesting and authorization key but now it's asking me to input my box credentials again even though I already did that on my desktop version of Rstudio. Any idea why it would be prompting for credentials again on Rstudio server version?

image

ijlyttle commented 4 years ago

This might be a long shot, and you would have already read about this, but are the versions of httr identical on both the server and on the local computer where you generate the boxr token?

jtraurig commented 4 years ago

Yeah. I did catch that in the instructions. They are the same version 1.4.2 unfortunately. If it helps, I've narrowed down in code where the prompt is happening. Screen shots below:

This is in box_auth image

And then I step into httr::oauth2.0_token() and the prompt happens at the Token2.0$new() call. Not that familiar with what is going on here. Any ideas what might be causing the credential prompt to open in another window.

Note, if I haven't said this before. I have followed the exact same steps using a local Rstudio Server version and have successfully authenticated, which is frustrating since it works there but not virtual machine.

nathancday commented 4 years ago

Using box_auth_service() is the proper way to handle this type of server-server authentication. I'd recommend going down that road.

Interactive OAuth was never meant for use on remote machines, but the copying of the token was an easy hack/work-around so we did it 🤷

jtraurig commented 4 years ago

No problem. Thanks for the help. I did eventually figure out a solution. The issue was related to the .box-oauth file which is just a rds file (which I'm sure you know). The .rds file has a function to generate a hash which should match the name of the list in the .rds file; however, the hash created on my windows machine was different than the hash created on the server. Because of this, the .boxr-oauth file was actually being ignored on the server. The hash generated on the server did not match the list name of the .rds file. I was able to work around this with a quick hack.

That said, the service route does appear to be a better path. Saving the json token on multiple machines is much easier than figuring the system differences for each machine.