Skip to content

Commit

Permalink
use basic auth and token auth if credentials set
Browse files Browse the repository at this point in the history
If a username and password are present in credentials add basic auth
headers. If a token is present in credentials authenticate with token
instead of temptoken.
  • Loading branch information
pld committed Feb 13, 2017
1 parent 7afe08c commit dae67d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
:milia-http-default-per-route "10"
:milia-http-threads "20"})

(defproject onaio/milia "0.3.27-SNAPSHOT"
(defproject onaio/milia "0.3.28-SNAPSHOT"
:description "The ona.io Clojure Web API Client."
:dependencies [;; CORE MILIA REQUIREMENTS
[cheshire "5.6.3"]
Expand Down
11 changes: 8 additions & 3 deletions src/milia/api/io.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
(let [stateful-method? (in? [:post :put :patch] method)
param-key (if stateful-method? :form-params :query-params)
;; With credentials always false
http-options (assoc http-options :with-credentials? false)]
;; If not JSON Params and not stateful and no-cache, add cache-buster
http-options (assoc http-options :with-credentials? false)
{:keys [username password]} *credentials*]
(cond-> http-options
;; If username and password are set use basic auth
(and username password)
(assoc :basic-auth {:username username :password password})
;; If not JSON Params and not stateful and no-cache, add cache-buster
(and no-cache?
(not (:json-params http-options))
(not stateful-method?))
Expand All @@ -48,7 +52,8 @@
"Builds request headers for the HTTP request by adding
Authorization, X-CSRFToken and Cache-control headers where necessary"
[& {:keys [get-crsftoken? must-revalidate? accept-header auth-token]}]
(let [temp-token (:temp-token *credentials*)]
(let [{:keys [token temp-token]} *credentials*
auth-token (or auth-token token)]
(into {} [(if auth-token
["Authorization" (str "Token " auth-token)]
(when (and (not-empty temp-token) (is-not-null?
Expand Down

0 comments on commit dae67d6

Please sign in to comment.