diff --git a/README.org b/README.org index ed5580e..dbabf72 100644 --- a/README.org +++ b/README.org @@ -19,14 +19,13 @@ wrap your routes with it: #+BEGIN_SRC clojure (defn get-auth-from-api-key [token] (when (= token "secret-api-key") - {:user "user-01" - :groups ["admin-id" "user-id"] - :username "username" - :group-names ["admin" "users"] - :admin true - :auth-type :api-key})) + {:user {:id "user-01" :name "username"} + :groups #{{:id "cisco" :name "Cisco"}} + :roles #{:admin :user} + :auth-type :api-key})) + (def app - (wrap-api-key-auth-fn handler get-auth-from-api-key)) + ((wrap-api-key-auth-fn get-auth-from-api-key) handler)) #+END_SRC When configured like this all requests with the header: @@ -39,11 +38,10 @@ will be modified to be passed to the handler with the new key `:api-key-info` containing: #+BEGIN_SRC clojure -{:user "user-01" - :groups ["admin-id" "user-id"] - :username "username" - :group-names ["admin" "users"] - :admin true} +{:user {:id "user-01" :name "username"} + :groups #{{:id "cisco" :name "Cisco"}} + :roles #{:admin :user} + :auth-type :api-key} #+END_SRC If the header contain an Authorization header with an unknown `api-key` the diff --git a/project.clj b/project.clj index 4547621..146d15b 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject threatgrid/ring-api-key-middleware "0.1.1-SNAPSHOT" +(defproject threatgrid/ring-api-key-middleware "0.1.2" :description "A simple middleware to deal with API keys Authentication" :url "http://github.com/threatgrid/ring-api-key-middleware" :license {:name "Eclipse Public License - v 1.0" diff --git a/src/ring_api_key_middleware/core.clj b/src/ring_api_key_middleware/core.clj index d8e4671..9e40c92 100644 --- a/src/ring_api_key_middleware/core.clj +++ b/src/ring_api_key_middleware/core.clj @@ -18,10 +18,12 @@ (defn wrap-api-key-fn "I check " - [handler get-infos] - (fn [request] - (if-let [api-key (get-api-key request)] - (if-let [infos (get-infos api-key)] - (handler (assoc request :api-key-infos infos)) - (unauthorized "wrong access key")) - (handler request)))) + [get-infos] + (fn + [handler] + (fn [request] + (if-let [api-key (get-api-key request)] + (if-let [infos (get-infos api-key)] + (handler (assoc request :api-key-infos infos)) + (unauthorized "wrong access key")) + (handler request)))))