Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

Latest httr changes to OAuth breaks rfigshare? #70

Closed
cboettig opened this issue Mar 13, 2014 · 20 comments
Closed

Latest httr changes to OAuth breaks rfigshare? #70

cboettig opened this issue Mar 13, 2014 · 20 comments
Labels
Milestone

Comments

@cboettig
Copy link
Collaborator

I think @hadley mentioned some changes to OAuth in httr he wanted folks to test recently. I installed the current github httr locally and now cannot authenticate rfigshare. @karthik or @emhart can you check/confirm if you can still authenticate rfigshare with the latest httr build? Thanks.

@cboettig cboettig added the bug label Mar 13, 2014
@sckott
Copy link
Contributor

sckott commented Mar 13, 2014

Yeah, it broke stuff in rgauges, had to change process of passing in key via accept header

@cboettig
Copy link
Collaborator Author

@sckott thanks, can you link me to an example of the changes you had to make? Might speed up my debugging. Were the changes backwards compatible with earlier httr builds?

@karthik
Copy link
Contributor

karthik commented Mar 13, 2014

@cboettig It did break rgauges right away (only noticed because I was trying to get some metrics for Josh). Just tried with rfigshare now. Auth works fine for me and so does object creation and file upload.

rfigshare_0.2-8 and httr_0.3

@sckott
Copy link
Contributor

sckott commented Mar 13, 2014

So rgauges worked fine with the CRAN version off httr 0.2, but not with the dev version.

Just had to change https://github.com/ropensci/rgauges/blob/a0cc44986b18e031a3158f1a1f31426be6f561f7/R/me.R#L14

GET(url=url, config=list(httpheader=paste0('X-Gauges-Token: ',key))

To this https://github.com/ropensci/rgauges/blob/master/R/gs_me.R#L15

GET(url=url, add_headers('X-Gauges-Token' = key))

and I do c(add_headers(...), callopts) to pass in curl debugging params

Apparently config=add_headers is the preferred method

@cboettig
Copy link
Collaborator Author

@karthik weird, I'm also running rfigshare_0.2-8 and httr_0.3, but no go (with either our testing credentials or my own).

fs_auth()
Error: Deprecated: supply token object to config directly

Enter a frame number, or 0 to exit   

1: fs_auth()
2: sign_oauth1.0(myapp, token = token, token_secret = token_secret)

@karthik
Copy link
Contributor

karthik commented Mar 13, 2014

other attached packages:
[1] httr_0.3          rfigshare_0.2-8   devtools_1.4.1.99 knitr_1.5         plyr_1.8.1       
[6] reshape2_1.2.2    ggplot2_0.9.3.1   coyote_0.1  
> fs_auth()
Error: Deprecated: supply token object to config directly

Very odd. So my Macbook Pro, i.e. couch laptop (where I tried earlier) is R 3.0.2 and things worked correctly. My Macbook air is R 3.0.3 and I get the same error as you.

@hadley
Copy link

hadley commented Mar 14, 2014

We should definitely talk about this at the hack-at-it. I think the new caching system in httr will eliminate some of the hassle here, and there are some larger architectural patterns that I think you'd benefit from.

@cboettig
Copy link
Collaborator Author

Sounds awesome, looking forward to it.

Meanwhile, anything about the OAuth1 error on upgrading to R 3.0.3 sound
familiar? Not sure where to begin debugging this one...


Carl Boettiger
http://carlboettiger.info

sent from mobile device; my apologies for any terseness or typos
On Mar 13, 2014 5:13 PM, "Hadley Wickham" [email protected] wrote:

We should definitely talk about this at the hack-at-it. I think the new
caching system in httr will eliminate some of the hassle here, and there
are some larger architectural patterns that I think you'd benefit from.

Reply to this email directly or view it on GitHubhttps://github.com//issues/70#issuecomment-37602839
.

@hadley
Copy link

hadley commented Mar 14, 2014

I don't understand how it couldn't currently be triggering errors since that function no longer works (ever). (But I think I have a way to make it work, let me try today)

@cboettig
Copy link
Collaborator Author

@hadley Looks like it's been too long since I looked at the httr interface! When I started this package the command was still called sign_ouath1.0 I think; I haven't updated in since the spelling was fixed! still, seemed to be in working order for our tests until recently.

The new mechanism with caching looks great. I see you have the function oauth1.0_token(), but is there a (exported) function like sign_oauth1.0 that can just take the token and private token directly without me having to do the handshake?

I realize your caching of tokens avoids having to repeat the handshake, something we were accomplishing before by just storing the token and private token along with the key and secret key in .Rprofile or so. When running in batch mode or across different remote machines it seems nice to just be able to give the tokens directly and know you won't be asked for interactive authentication.

Also, when I try the new oauth1.0_token() with figshare, I'm getting an error I didn't anticipate.

  request <- "request_token"
  authorize <- "authorize" 
  access <- "access_token"
  base_url <- "http://api.figshare.com/v1/pbl/oauth"
  endpoint <- oauth_endpoint(request, authorize, access, base_url=base_url)
  # endpoint <- oauth_endpoint(NULL, authorize, access, base_url=base_url) # tried this too since docs say oauth 1 doesn't need a request token? a bit confused, no dice.  

  myapp <- oauth_app("rfigshare", key = cKey, secret=cSecret)
  token <- oauth1.0_token(endpoint, myapp)

This takes me to the figshare website where I sign in and click "allow" as expected, then R gives me the error:

 token <- oauth1.0_token(endpoint, myapp)
Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Authentication complete.
Error in init_oauth1.0(endpoint, app, permission = params$permission) : 
  client error: (405) Method Not Allowed

Thanks much for any help or hints!

@cboettig cboettig added this to the v0.3 milestone Mar 14, 2014
@hadley
Copy link

hadley commented Mar 14, 2014

Just pushed a fix, so that you can use sign_oauth_1.0() again. I tested it with the following code:

myapp <- oauth_app("rfigshare", 
  key = getOption("FigshareKey"), 
  secret = getOption("FigsharePrivateKey"))

oauth <- sign_oauth1.0(myapp, token = getOption("FigshareToken"), 
  token_secret = getOption("FigsharePrivateToken"))

r <- GET("http://api.figshare.com/v1/my_data/articles", oauth)
stop_for_status(r)  

@hadley
Copy link

hadley commented Mar 14, 2014

@cboettig Hmmm, that error you're seeing is because I'm using a GET and figshare wants a POST (which I see is what the spec encourages, but doesn't require)

@hadley
Copy link

hadley commented Mar 14, 2014

I just pushed a fix - let me know if if works for you (it works for me with figshare, twitter and vimeo)

@karthik
Copy link
Contributor

karthik commented Mar 14, 2014

@hadley @cboettig Everything works correctly again on R 3.0.3, httr_0.3 and rfigshare_0.2-8.
Thank you!

@cboettig
Copy link
Collaborator Author

@hadley awesome; working for me as well, thanks much for the quick fix.

@cboettig
Copy link
Collaborator Author

Hmm, this was working this morning, and now I'm getting the error:

> fs_auth()
Error: cache should be length 1 vector

with trace

Enter a frame number, or 0 to exit   

1: fs_auth()
2: oauth1.0_token(endpoint, myapp)
3: new_token(Token1.0, endpoint, app, params, cache = cache)
4: use_cache(cache)

No idea what is causing this, seems to be related to httr's own caching getting confused with the already stored crendentials? @hadley @karthik can you replicate this error or have any ideas what might be going on here?

My sessionInfo:

R version 3.0.3 (2014-03-06)
Platform: x86_64-pc-linux-gnu (64-bit)

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

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

other attached packages:
[1] rfigshare_0.2-8     knitcitations_0.5-0 bibtex_0.3-6       
[4] knitr_1.5           devtools_1.4.1.99  

loaded via a namespace (and not attached):
 [1] MASS_7.3-29        RColorBrewer_1.0-5 RCurl_1.95-4.1     RJSONIO_1.0-3     
 [5] XML_3.98-1.1       colorspace_1.2-4   dichromat_2.0-0    digest_0.6.3      
 [9] evaluate_0.5.1     formatR_0.10       ggplot2_0.9.3.1    grid_3.0.3        
[13] gtable_0.1.2       httr_0.3           labeling_0.2       memoise_0.1       
[17] munsell_0.4.2      parallel_3.0.3     plyr_1.8           proto_0.3-10      
[21] reshape2_1.2.2     rjson_0.2.13       scales_0.2.3       stringr_0.6.2     
[25] tools_3.0.3        whisker_0.3-2      xtable_1.8-1       yaml_2.1.8      

@karthik
Copy link
Contributor

karthik commented Mar 16, 2014

Just a second ago:

> library(rfigshare)
> fs_auth()
Authentication successful

My session Info:

> sessionInfo()
R version 3.0.3 (2014-03-06)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] rfigshare_0.2-8   devtools_1.4.1.99 knitr_1.5         plyr_1.8.1
[5] reshape2_1.2.2    ggplot2_0.9.3.1   coyote_0.1

loaded via a namespace (and not attached):
 [1] colorspace_1.2-4   dichromat_2.0-0    digest_0.6.4       evaluate_0.5.1
 [5] formatR_0.10       grid_3.0.3         gtable_0.1.2       httr_0.3
 [9] labeling_0.2       MASS_7.3-30        memoise_0.1        munsell_0.4.2
[13] parallel_3.0.3     proto_0.3-10       RColorBrewer_1.0-5 Rcpp_0.11.1
[17] RCurl_1.95-4.1     RJSONIO_1.0-3      scales_0.2.3       stringr_0.6.2
[21] tools_3.0.3        whisker_0.3-2      XML_3.95-0.2       yaml_2.1.11

@karthik
Copy link
Contributor

karthik commented Mar 16, 2014

Have you tried installing httr again from Hadley's repo? He may not have bumped up the version number after adding sign_oauth_1.0() back (highly plausible).

@cboettig
Copy link
Collaborator Author

Yes, I did and it worked this morning just fine... Perhaps in doing so it
also tried to cache the credentials and got confused? I'll see if I can see
how to clear or toggle httr caching


Carl Boettiger
http://carlboettiger.info

sent from mobile device; my apologies for any terseness or typos
On Mar 16, 2014 3:09 PM, "Karthik Ram" [email protected] wrote:

Have you tried installing httr again from Hadley's repo? He may not have
bumped up the version number after adding sign_oauth_1.0() back (highly
plausible).

Reply to this email directly or view it on GitHubhttps://github.com//issues/70#issuecomment-37772930
.

@cboettig
Copy link
Collaborator Author

Whoops, was testing with the rfigshare branch in which I had already tried migrating to the oauth1.0_token method I mentioned in #70 (comment) before sign_oauth1.0() was restored. silly me, all working now.

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

No branches or pull requests

4 participants