Skip to content
/ oauth Public

OAuth client for the R statistical programming language

Notifications You must be signed in to change notification settings

noahhl/oauth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

oauth: a simple oauth client for R

This is a simple implementation of an Oauth 1.0 and Oauth 2.0 client for the R statistical programming language. External dependencies are limited to RCurl and digest. Syntax is intended to be straightforward.

Use at your own risk. Please report errors, feature requests, etc. using Github issues.

Installation:

  git clone git@github.com:noahhl/oauth.git
  R CMD INSTALL oauth

Usage:

1) Create a list with the parameters for your application, structured as below:

For Oauth 1.0:


params <- list(oauth_consumer_key = “yourconsumerkey”,
oauth_consumer_secret = “yourconsumersecret”,
oauth_callback=“http://somedomain.com”,
oauth_signature_method = “HMAC-SHA1”,
oauth_version=“1.0”,
server = list(
#To get request token
initiate = “https://api.twitter.com/oauth/request_token”,
#For user authentication
auth = “https://api.twitter.com/oauth/authorize”,
#For access token
token = “https://api.twitter.com/oauth/access_token”)
)

For Oauth 2.0:


params <- list(
client_id = “6b46fbe891254613e95basdfsadfasdc220e68”,
client_secret = “c28da69a504eeeaasdfsafdas48fc605b3cac5”,
type = “web_server”,
redirect_uri = “http://37signals.com/”,
#For user to authorize app
request_uri = “https://launchpad.37signals.com/authorization/new”,
#To get token
token_uri = “https://launchpad.37signals.com/authorization/token”
)

2) Run the Authorize() command, passing it your parameters, optionally with parameters to enable “noisy” output or to specify not to save credentials beyond this session. Recapture the output back into params. If save=T and file=NULL, the credentials will be saved in the local directory in a file name like .oauthparams_api.twitter.Rdata.

For Oauth 2 implementations, prepend Authorize with Oauth2. You can use the refresh token by adding the “refresh=F” option.

Oauth 1:


params <- Authorize(params, noisy=F, save=T, file=NULL)

Oauth 2:


params <- Oauth2Authorize(params, noisy=F, save=T, file=NULL, refresh=FALSE)

3) If you’ve previously auth’d, you can reload the credentials using the LoadCredentials(site) or LoadCredentials(file) command, passing it either a path to a previously saved credential file, or the name of the service you are trying to auth for (e.g., api.twitter).

  LoadCredentials(site="api.twitter")
  LoadCredentials(file="~/mytwittercredentials")

4) Make a request, using the MakeRequest(params, resource, method, request=NULL, noisy=F) command. For Oauth 2 implementations, prepend MakeRequest with Oauth2 (e.g., Oauth2MakeRequest); parameters are the same for Oauth1 and Oauth2.

Some examples for <a href = “http://developer.twitter.com/doc/”>Twitter are provided below. Briefly:


  • params are the resultant params from an Authorize() command, or the params loaded from LoadCredentials

  • resource is the URL of the resource you are trying to access. If this is a request in which you would pass request parameters (e.g., ?search=abcdefg), do not include those parameters in the resource URL.

  • method is one of “GET”, “POST”, “PUT”, or “DELETE”.

  • request are any request parameters provided as a named character vector (e.g., c(search="Test", since="yesterday"))
#Verify credentials
MakeRequest(params, "http://api.twitter.com/1/account/verify_credentials.json", "GET")

#Send a tweet
MakeRequest(params, "http://api.twitter.com/1/statuses/update.json", "POST", request=c(status="#rstats is my hero."))

A demo can be accessed by loading the oauth package and running demo("term-ie_demo").

Acknowledgements / license

Github user twittoru provided the included HMAC-SHA1 implementation, found at: https://gist.github.com/586468

This package is made available under the MIT license:

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

About

OAuth client for the R statistical programming language

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages