File tree Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -117,6 +117,9 @@ More example requests:
117117(client/get " http://site.com/protected" {:basic-auth [" user" " pass" ]})
118118(client/get " http://site.com/protected" {:basic-auth " user:pass" })
119119
120+ ; ; OAuth 2
121+ (client/get " http://site.com/protected" {:oauth-token " secret-token" })
122+
120123; ; Query parameters
121124(client/get " http://site.com/search" {:query-params {" q" " foo, bar" }})
122125
Original file line number Diff line number Diff line change 306306 (basic-auth-value basic-auth))))
307307 (client req))))
308308
309+ (defn wrap-oauth [client]
310+ (fn [req]
311+ (if-let [oauth-token (:oauth-token req)]
312+ (client (-> req (dissoc :oauth-token )
313+ (assoc-in [:headers " Authorization" ]
314+ (str " Bearer " oauth-token))))
315+ (client req))))
316+
317+
309318(defn parse-user-info [user-info]
310319 (when user-info
311320 (str/split user-info #":" )))
380389 (-> request
381390 wrap-query-params
382391 wrap-basic-auth
392+ wrap-oauth
383393 wrap-user-info
384394 wrap-url
385395 wrap-redirects
Original file line number Diff line number Diff line change 279279 (is-passed client/wrap-basic-auth
280280 {:uri " /foo" }))
281281
282+ (deftest apply-on-oauth
283+ (is-applied client/wrap-oauth
284+ {:oauth-token " my-token" }
285+ {:headers {" Authorization"
286+ " Bearer my-token" }}))
287+
288+ (deftest pass-on-no-oauth
289+ (is-passed client/wrap-oauth
290+ {:uri " /foo" }))
291+
292+
282293(deftest apply-on-method
283294 (let [m-client (client/wrap-method identity)
284295 echo (m-client {:key :val :method :post })]
You can’t perform that action at this time.
0 commit comments