Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'clj-1.3'

  • Loading branch information...
commit 30be3751ca9d6db49ffd84017fa78ee58aa1af19 2 parents cf8d11c + 7d88e38
@roman authored
View
1  .gitignore
@@ -4,4 +4,5 @@ lib
classes
*.jar
pom.xml
+.lein-*
View
7 project.clj
@@ -1,10 +1,9 @@
(defproject clj-oauth "1.2.10-SNAPSHOT"
:description "OAuth support for Clojure"
- :dependencies [[org.clojure/clojure "1.2.0"]
- [org.clojure/clojure-contrib "1.2.0"]
+ :dependencies [[org.clojure/clojure "1.3.0"]
[com.twinql.clojure/clj-apache-http "2.3.1"]
[org.apache.httpcomponents/httpclient "4.1"]
[org.apache.httpcomponents/httpcore "4.1"]
- [org.apache.httpcomponents/httpmime "4.1"]]
- :dev-dependencies [[swank-clojure "1.3.0-SNAPSHOT"]])
+ [org.apache.httpcomponents/httpmime "4.1"]])
+
View
10 src/oauth/client.clj
@@ -5,7 +5,7 @@
(:require [oauth.digest :as digest]
[oauth.signature :as sig]
[com.twinql.clojure.http :as http])
- (:use [clojure.contrib.string :only [as-str join split upper-case]]))
+ (:use [clojure.string :only [join split upper-case]]))
(declare success-content
authorization-header)
@@ -46,11 +46,11 @@
(into {}
(if-let [body (http/entity-as entity :string status)]
(map (fn [kv]
- (let [[k v] (split #"=" kv)
+ (let [[k v] (split kv #"=")
k (or k "")
v (or v "")]
[(keyword (sig/url-decode k)) (sig/url-decode v)]))
- (split #"&" body))
+ (split body #"&"))
nil)))
(defn request-token
@@ -147,7 +147,7 @@ Authorization HTTP header or added as query parameters to the request."
unsigned-oauth-params)
signature (sig/sign consumer
(sig/base-string (-> request-method
- as-str
+ sig/as-str
upper-case)
request-uri
unsigned-params)
@@ -158,7 +158,7 @@ Authorization HTTP header or added as query parameters to the request."
"OAuth credentials formatted for the Authorization HTTP header."
([oauth-params]
(str "OAuth " (join ", " (map (fn [[k v]]
- (str (-> k as-str sig/url-encode) "=\"" (-> v as-str sig/url-encode) "\""))
+ (str (-> k sig/as-str sig/url-encode) "=\"" (-> v sig/as-str sig/url-encode) "\""))
oauth-params))))
([oauth-params realm]
(authorization-header (assoc oauth-params realm))))
View
10 src/oauth/signature.clj
@@ -3,7 +3,7 @@
:doc "OAuth client library for Clojure."}
oauth.signature
(:require [oauth.digest :as digest])
- (:use [clojure.contrib.string :only [join as-str]]))
+ (:use [clojure.string :only [join]]))
(declare rand-str
base-string
@@ -11,6 +11,14 @@
url-encode
oauth-params)
+(defn- named? [a]
+ (instance? clojure.lang.Named a))
+
+(defn as-str [a]
+ (if (named? a)
+ (name a)
+ (str a)))
+
(def secure-random (java.security.SecureRandom/getInstance "SHA1PRNG"))
(defn rand-str
View
4 test/oauth/client_test.clj
@@ -3,7 +3,7 @@
[oauth.signature :as sig]
:reload-all)
(:use clojure.test
- [clojure.contrib.pprint :only [pprint]]))
+ [clojure.pprint :only [pprint]]))
(deftest ^{:doc "Test creation of authorization header for request_token access."}
request-access-authorization-header
@@ -68,4 +68,4 @@
t "nnch734d00sl2jdk"]
;; The approval URL should only use the :oauth_token in the User approval URI
(is (= "https://api.twitter.com/oauth/authorize?oauth_token=nnch734d00sl2jdk"
- (oc/user-approval-uri c t)))))
+ (oc/user-approval-uri c t)))))
View
12 test/oauth/signature_test.clj
@@ -12,6 +12,12 @@
:oauth_version "1.0"})
(deftest
+ as-str-function
+ (is (= (sig/as-str :hello) "hello"))
+ (is (= (sig/as-str 3412) "3412"))
+ (is (= (sig/as-str 'hello) "hello")))
+
+(deftest
signature-methods
(is (= (sig/signature-methods :hmac-sha1) "HMAC-SHA1")))
@@ -242,11 +248,11 @@
url-form-encode
(is (= (sig/url-form-encode {}) ""))
(is (= (sig/url-form-encode {"hello" "there"}) "hello=there"))
- (is (= (sig/url-form-encode {"hello" "there" "name" "Bill" }) "hello=there&name=Bill"))
+ (is (= (sig/url-form-encode (sort {"hello" "there" "name" "Bill" })) "hello=there&name=Bill"))
(is (= (sig/url-form-encode {:hello "there"}) "hello=there"))
- (is (= (sig/url-form-encode {:hello "there" :name "Bill" }) "hello=there&name=Bill"))
+ (is (= (sig/url-form-encode (sort {:hello "there" :name "Bill" })) "hello=there&name=Bill"))
(is (= (sig/url-form-encode {:hello "there"}) "hello=there"))
- (is (= (sig/url-form-encode {:hello "there" :name "Bill Smith" }) "hello=there&name=Bill%20Smith")))
+ (is (= (sig/url-form-encode (sort {:hello "there" :name "Bill Smith" })) "hello=there&name=Bill%20Smith")))
Please sign in to comment.
Something went wrong with that request. Please try again.