2015-01-13 1 views
1

Я пытаюсь выполнить аутентификацию с помощью интерактивного рабочего процесса Cemerick Friend. Я получаю следующее сообщение об ошибке, когда я отправляю на мой Логин-URI:Интерактивная форма Cemerick Friend - Неопознанное тело

2015-01-13 12:51:22.945:WARN:oejs.AbstractHttpConnection:/api/login 
java.lang.Exception: Unrecognized body: {:error "Wrong credentials", :uri {:ssl-client-cert nil, :remote-addr "0:0:0:0:0:0:0:1", :params {}, :headers {"origin" "http://localhost:3000", "host" "localhost:3000", "user-agent" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36 OPR/26.0.1656.60", "content-type" "application/json", "content-length" "42", "referer" "http://localhost:3000/?username=friend&password=clojure", "connection" "keep-alive", "accept" "*/*", "accept-language" "en-US,en;q=0.8", "accept-encoding" "gzip, deflate, lzma", "dnt" "1"}, :server-port 3000, :content-length 42, :form-params {}, :query-params {}, :content-type "application/json", :character-encoding nil, :uri "/api/login", :server-name "localhost", :query-string nil, :body #<HttpInput [email protected]>, :scheme :http, :cemerick.friend/auth-config {:login-failure-handler #<handler$fn__5557 [email protected]>, :unauthorized-handler #<handler$fn__5555 [email protected]>, :allow-anon? true, :unauthenticated-handler #<handler$fn__5553 [email protected]>, :redirect-on-auth? false, :default-landing-uri "/", :login-uri "/api/login", :credential-fn #<handler$fn__5551 [email protected]>, :workflows [#<workflows$interactive_form$fn__5175 [email protected]>]}, :request-method :post}} 

Мой обработчик & код относящийся:

(ns myproject.core.handler 
    (:require [compojure.handler :as ch] 
      [ring.middleware.json :as rj] 
      [ring.util.response :as rr] 
      [cemerick.friend :as friend] 
      (cemerick.friend [workflows :as workflows] 
          [credentials :as creds]) 
      [myproject.core.route :as routes])) 

(def users {"friend" {:username "friend" 
         :password (creds/hash-bcrypt "clojure")}}) 

(def friend-options {:allow-anon? true 
        :redirect-on-auth? false 
        :login-failure-handler #(-> (rr/response {:error "Wrong credentials" :uri %}) (rr/status 401)) 
        :unauthenticated-handler #(-> (rr/response {:error "Unauthenticated" :uri %}) (rr/status 401)) 
        :login-uri "/api/login" 
        :default-landing-uri "/" 
        :unauthorized-handler #(-> (rr/response {:error "Unauthorized" :uri %}) (rr/status 401)) 
        :credential-fn #(creds/bcrypt-credential-fn users %) 
        :workflows [(workflows/interactive-form :redirect-on-auth? false)]}) 

(def secured-app 
    (-> (ch/api routes/api) 
     (rj/wrap-json-body :keywords? true) 
     (rj/wrap-json-response) 
     (friend/authenticate friend-options))) 

ClojureScript запуская логин:

(ns myproject.services.auth                                  
    (:require-macros [cljs.core.async.macros :refer [go]]) 
    (:require [cljs-http.client :as http]  
      [cljs.core.async :refer [<! >! chan put!]] 
      [myproject.core.store :as store])) 

(defn login [res username password]     
    (go (let [result (<! (http/post "/api/login" {:json-params {:username username :password password}}))] 
     (.log js/console (pr-str result)) 
     (if (= (:status result) 200) 
      (let [access (:body result)] 
      (swap! store/app-state assoc :access access) 
      (swap! store/app-state assoc :view :tasks) 
      (>! res true))  
      (>! res false))))) 

(defn active-access [res]  
    (go (let [access (<! (http/get "/api/session"))] 
     (if (= (:status access) 200)   
      (>! res (:body access))    
      (>! res false))))) 

Любые идеи ?

ответ

1

Оказалось, что проблема была в порядке моих посредников. Мне нужно было wrap-json-bodyпослеfriend-authenticate.