Permalink
Browse files

fixes #5, removed extraneous extract-code function, as Ring middlewar…

…e (params/keyword-params) handles everything. Removed unnecessary test and restructured test code to support ring middleware.
  • Loading branch information...
1 parent e717167 commit b485560c65d880d344a1d440172ee244beeb6a43 @ddellacosta ddellacosta committed Mar 31, 2013
Showing with 20 additions and 20 deletions.
  1. +1 −0 .midje.clj
  2. +1 −0 project.clj
  3. +4 −8 src/friend_oauth2/workflow.clj
  4. +14 −12 test/friend_oauth2/workflow_facts.clj
View
@@ -0,0 +1 @@
+;;(change-defaults :fact-filter :fact-on)
View
@@ -13,4 +13,5 @@
[codox "0.6.4"]]
:profiles
{:dev {:dependencies [[ring-mock "0.1.3"]
+ [ring "1.2.0-beta2"]
[midje "1.5.0"]]}})
@@ -22,13 +22,7 @@
[uri-config code]
(assoc-in (uri-config :query) [:code] code))
-;; http://tools.ietf.org/html/draft-ietf-oauth-v2-31#section-4.1.2
-(defn extract-code
- "Returns the authentication code from a request query-string"
- [request]
- (if-let [query-string (request :query-string)]
- ((codec/form-decode query-string) "code")
- nil))
+
;; http://tools.ietf.org/html/draft-ietf-oauth-v2-31#section-5.1
(defn extract-access-token
@@ -59,7 +53,9 @@
;; Steps 2 and 3:
;; accept auth code callback, get access_token (via POST)
- (if-let [code (extract-code request)]
+
+ ;; http://tools.ietf.org/html/draft-ietf-oauth-v2-31#section-4.1.2
+ (if-let [code (-> request :params :code)]
(let [access-token-uri ((config :uri-config) :access-token-uri)
token-url (assoc-in access-token-uri [:query]
(replace-authorization-code access-token-uri code))
@@ -3,6 +3,8 @@
(:require [friend-oauth2.workflow :as friend-oauth2]
[cemerick.friend :as friend]
[clj-http.client :as client]
+ [ring.middleware.params :as ring-params]
+ [ring.middleware.keyword-params :as ring-keyword-params]
[ring.mock.request :as ring-mock]
[ring.util.codec :as codec]
[cheshire.core :as j]))
@@ -46,10 +48,12 @@
;; http://tools.ietf.org/html/draft-ietf-oauth-v2-31#section-4.1.2
(defn redirect-request-fixture
[redirect-uri]
- (ring-mock/content-type
- (ring-mock/request :get redirect-uri
- {:code "my-code"})
- "application/x-www-form-urlencoded"))
+ (ring-keyword-params/keyword-params-request
+ (ring-params/params-request
+ (ring-mock/content-type
+ (ring-mock/request :get redirect-uri
+ {:code "my-code"})
+ "application/x-www-form-urlencoded"))))
(def default-redirect "/redirect")
@@ -103,13 +107,11 @@
=> "my-access-token")
(fact
- "Extracts the code from the initial authorization request"
- (friend-oauth2/extract-code (redirect-with-default-redirect-uri))
- => "my-code")
-
-(fact
"Returns nil if there is no code in the request"
- (friend-oauth2/extract-code (ring-mock/request :get default-redirect))
+ ;; No longer necessary since ring params/keyword-params handles this for us.
+ ;; Not sure if this test is necessary anymore either, but leaving in for now.
+ ;; (friend-oauth2/extract-code (ring-mock/request :get default-redirect))
+ (-> (ring-mock/request :get default-redirect) :params :code)
=> nil)
(fact
@@ -150,7 +152,7 @@
(fact
"extract-access-token is used for access-token-parsefn if none is passed in."
(default-workflow-function
- (query-string-to-params (redirect-with-default-redirect-uri)))
+ (redirect-with-default-redirect-uri))
=> {:identity "my-access-token", :access_token "my-access-token"}
(provided
(friend-oauth2/extract-access-token access-token-response-fixture)
@@ -159,7 +161,7 @@
(fact
"If there is a code in the request it posts to the token-uri"
(default-workflow-function
- (query-string-to-params (redirect-with-default-redirect-uri)))
+ (redirect-with-default-redirect-uri))
=> {:identity "my-access-token", :access_token "my-access-token"}
(provided
(client/post "http://example.com"

0 comments on commit b485560

Please sign in to comment.