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

Consider supporting Rstudio server #23

Closed
brendan-r opened this issue Apr 8, 2015 · 10 comments · Fixed by #105
Closed

Consider supporting Rstudio server #23

brendan-r opened this issue Apr 8, 2015 · 10 comments · Fixed by #105

Comments

@brendan-r
Copy link
Collaborator

At the moment, the auth process gets as far as launching a new browser window and the 'grant access' button. However, R can't read the results.

The tab stayed open with a URL like this: http://localhost:1410/?state=2WnJOcTuKG&code=cYWy4jBcMc0cHDkw3DjJcEuUVh1MiX1w

It may well be that this contains enough information for a user to copy and paste it back in to the console, and for a httr token object to be constructed.

@brendan-r brendan-r self-assigned this Apr 8, 2015
@brendan-r
Copy link
Collaborator Author

The following env vars (Sys.getenv()) are likely to be useful (tested on Ubuntu):

  • SSH_CONNECTION
    • (only present if there is one)
  • RSTUDIO
    • (present for both server and desktop)
  • RSTUDIO_HTTP_REFERER
    • (present for rstudio server only)

@dgarciam
Copy link

I was actually looking forward on using box-r on rstudio server.
Since Linux doesnt have a box.com client, this was a excellent solution to this, specially since all the data i want to grab is for a shiny app.
Alas! Will have to wait until you figure this out.
Thanks for the package!

@brendan-r
Copy link
Collaborator Author

In the meantime, you could try setting up your account on a local machine, and then copying over the generated token file (~/.boxr-oauth) to the same place on the server. Once you've done this, running box_auth() from rstudio-server should detect it and authorise you. I haven't tested this myself, but I've seen it discussed as a work-around for other OAuth2.0/httr packages. Let me know how you get on!

@dgarciam
Copy link

Thanks for the tip. I registered on a windows laptop i had around and got the .box-auth.
But it didnt work all the way to validate me.

First of all, it didnt work just copying the .box-oauth. Besides de .boxr-oauth i needed to copy ~/.Renviron as well (was a file with only two lines that contained my box id and box secret).
After that, here are my results:

library(boxr)
Welcome to boxr 0.2.9!
Bug reports: https://github.com/brendan-R/boxr/issues

box_auth()
Reading client id from .Renviron
Reading client secret from .Renviron
Auto-refreshing stale OAuth token.
Error in refresh_oauth2.0(self$endpoint, self$app, self$credentials) :
client error: (400) Bad Request

Can you point me out to the page where you saw this workaround? perhaps i could read a bit from them to see if i needed to do something else.

Thanks!

@dgarciam
Copy link

Well, what do you know.
I tried again and this time it did work.

  1. Refresh on PC
  2. Right away copy token
  3. box_auth()

library(boxr)
Welcome to boxr 0.2.9!
Bug reports: https://github.com/brendan-R/boxr/issues

box_auth()
Reading client id from .Renviron
Reading client secret from .Renviron
boxr: Authenticated at box.com as XXX XXXXX (xxx.xxxxxa@xxxxxxxxxxxxxx.com)

wonder if i will able to refresh from rstudio now.

Thanks for the pointers! w/o your guidance i would be stuck! Keep the good work and i hope you can sort this hurdle in the near future!

@brendan-r
Copy link
Collaborator Author

Very glad it worked! 😄

Based on my (wobbly) understanding of OAuth2.0, if auth'ing via two machines does give you problems, setting up separate 'Apps' at box.com (and using separate tokens) is likely to stop this happening. This is more of an issue with API design than the R package I'm afraid.

@terrytangyuan
Copy link

Hi Brendan, do you have any progress on this?

I am trying to use it without needing to open the browser and click "yes" to authorize.

@brendan-r
Copy link
Collaborator Author

I'm afraid having to do the browser part somewhere is the essence of OAuth2.0; there's no way around it with the box.com API.

The token-copying method described above, while annoyingly manual, seems to be the recommended behaviour for similar packages, such as rdrop2. It seems that the googlesheets team made some progress towards making the token-copying part unnecessary, but it doesn't look like it's quite a solved problem yet (though I may be mistaken). I have a suspicion that you'd need to get into the internals of rstudio-server itself to make it work properly.

I'm afraid I'll be unable to spend significant time on this in the near term, but if it's a pressing need for you and you'd like to have a crack at it, I'd be happy to consider a pull request.

@terrytangyuan
Copy link

Got it. Thanks. Great job on this package. :-)

@brendan-r
Copy link
Collaborator Author

Copy and paste method described here (h/t @nwstephens):
https://support.rstudio.com/hc/en-us/articles/217952868

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants