Skip to content

Commit b45fede

Browse files
committed
use basic auth and token auth if credentials set
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.
1 parent 7afe08c commit b45fede

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
:milia-http-default-per-route "10"
99
:milia-http-threads "20"})
1010

11-
(defproject onaio/milia "0.3.27-SNAPSHOT"
11+
(defproject onaio/milia "0.3.28-SNAPSHOT"
1212
:description "The ona.io Clojure Web API Client."
1313
:dependencies [;; CORE MILIA REQUIREMENTS
1414
[cheshire "5.6.3"]

src/milia/api/io.cljs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@
2121
(let [stateful-method? (in? [:post :put :patch] method)
2222
param-key (if stateful-method? :form-params :query-params)
2323
;; With credentials always false
24-
http-options (assoc http-options :with-credentials? false)]
25-
;; If not JSON Params and not stateful and no-cache, add cache-buster
24+
http-options (assoc http-options :with-credentials? false)
25+
{:keys [username password]} *credentials*]
2626
(cond-> http-options
27+
;; If username and password are set use basic auth
28+
(assoc :basic-auth {:username username :password password})
29+
(and username password)
30+
;; If not JSON Params and not stateful and no-cache, add cache-buster
2731
(and no-cache?
2832
(not (:json-params http-options))
2933
(not stateful-method?))
@@ -48,7 +52,8 @@
4852
"Builds request headers for the HTTP request by adding
4953
Authorization, X-CSRFToken and Cache-control headers where necessary"
5054
[& {:keys [get-crsftoken? must-revalidate? accept-header auth-token]}]
51-
(let [temp-token (:temp-token *credentials*)]
55+
(let [{:keys [token temp-token]} *credentials*
56+
auth-token (or auth-token token)]
5257
(into {} [(if auth-token
5358
["Authorization" (str "Token " auth-token)]
5459
(when (and (not-empty temp-token) (is-not-null?

0 commit comments

Comments
 (0)