Skip to content
Browse files

Handshaking requires different escaping

  • Loading branch information...
1 parent 927e5fe commit 10d58f6f80b80ab98d08a01d371648f1ec170938 @geoffjentry committed
Showing with 22 additions and 16 deletions.
  1. +1 −1 DESCRIPTION
  2. +15 −12 R/ROauth.R
  3. +6 −3 R/sign.R
View
2 DESCRIPTION
@@ -3,7 +3,7 @@ Title: R interface for OAuth
Description: This package provides an interface to the OAuth 1.0
specification, allowing users to authenticate via OAuth to the
server of their choice.
-Version: 0.9.1
+Version: 0.9.2
Author: Jeff Gentry <geoffjentry@gmail.com>, Duncan Temple Lang
<duncan@r-project.org>
Maintainer: Jeff Gentry <geoffjentry@gmail.com>
View
27 R/ROauth.R
@@ -29,12 +29,13 @@ setRefClass("OAuth",
with their web browser, entering a PIN into
this function.
'
- handshakeComplete <<- FALSE
- signMethod <<- signMethod
+ .self$handshakeComplete <- FALSE
+ .self$signMethod <- signMethod
resp <- oauthPOST(.self$requestURL,
.self$consumerKey,
.self$consumerSecret,
- NULL, NULL, signMethod=.self$signMethod, curl=curl, ...)
+ NULL, NULL, signMethod=.self$signMethod, curl=curl,
+ handshakeComplete=.self$handshakeComplete, ...)
vals <- parseResponse(resp)
if (!all(c('oauth_token', 'oauth_token_secret') %in%
names(vals))) {
@@ -42,8 +43,8 @@ setRefClass("OAuth",
"check your consumerKey and consumerSecret",
" and try again.")
}
- oauthKey <<- vals['oauth_token']
- oauthSecret <<- vals['oauth_token_secret']
+ .self$oauthKey <- vals["oauth_token"]
+ .self$oauthSecret <- vals["oauth_token_secret"]
if (.self$needsVerifier) {
verifyURL <- paste(.self$authURL, "?oauth_token=",
oauthKey, sep='')
@@ -52,12 +53,13 @@ setRefClass("OAuth",
verifyURL,
"\nWhen complete, record the PIN given ",
"to you and provide it here: ", sep='')
- verifier <<- readline(prompt=msg)
+ .self$verifier <- readline(prompt=msg)
}
params <- c(oauth_verifier=.self$verifier)
resp <- oauthPOST(.self$accessURL, .self$consumerKey, .self$consumerSecret,
.self$oauthKey, .self$oauthSecret, signMethod=.self$signMethod,
- curl=getCurlHandle(), params=params, ...)
+ curl=getCurlHandle(), params=params, handshakeComplete=.self$handshakeComplete,
+ ...)
vals <- parseResponse(resp)
if (!all(c('oauth_token', 'oauth_token_secret') %in%
names(vals))) {
@@ -66,9 +68,9 @@ setRefClass("OAuth",
" this handshake & browser authorization to get",
" a new PIN.")
}
- oauthKey <<- vals['oauth_token']
- oauthSecret <<- vals['oauth_token_secret']
- handshakeComplete <<- TRUE
+ .self$oauthKey <- vals["oauth_token"]
+ .self$oauthSecret <- vals["oauth_token_secret"]
+ .self$handshakeComplete <- TRUE
},
isVerified = function() {
@@ -121,13 +123,14 @@ parseResponse <- function(response) {
oauthPOST <- function(url, consumerKey, consumerSecret,
oauthKey, oauthSecret, params=character(), customHeader = NULL,
- curl = getCurlHandle(), signMethod='HMAC', ...) {
+ curl = getCurlHandle(), signMethod='HMAC', handshakeComplete=TRUE, ...) {
if(is.null(curl))
curl <- getCurlHandle()
auth <- signRequest(url, params, consumerKey, consumerSecret,
oauthKey=oauthKey, oauthSecret=oauthSecret,
- httpMethod="POST", signMethod=signMethod)
+ httpMethod="POST", signMethod=signMethod,
+ handshakeComplete=handshakeComplete)
opts <- list(...)
## post ,specify the method
View
9 R/sign.R
@@ -2,7 +2,8 @@ signRequest <- function(url, params, consumerKey, consumerSecret,
oauthKey = "", oauthSecret = "", httpMethod = "GET",
signMethod = "HMAC", nonce = genNonce(),
timestamp = Sys.time(),
- escapeFun = curlPercentEncode) {
+ escapeFun = curlPercentEncode,
+ handshakeComplete=TRUE) {
## Sign an request made up of the URL, the parameters as a named character
## vector the consumer key and secret and the token and token secret.
httpMethod <- toupper(httpMethod)
@@ -42,11 +43,13 @@ signRequest <- function(url, params, consumerKey, consumerSecret,
sig <- signString(odat, okey, signMethod)
- if (httpMethod == "POST") {
+ ## Only perform the percent encode post-handshake when POSTing
+ if ((httpMethod == "POST") && (handshakeComplete)){
sig <- curlPercentEncode(sig)
}
params["oauth_signature"] <- sig
- params[grepl("^oauth_", names(params))]
+ ##
+ return(params[grepl("^oauth_", names(params))])
}
signString <- function(str, key, method) {

0 comments on commit 10d58f6

Please sign in to comment.
Something went wrong with that request. Please try again.