This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-17
Channels
- # aleph (3)
- # announcements (12)
- # beginners (80)
- # boot (3)
- # braveandtrue (16)
- # calva (3)
- # cider (82)
- # clojure (100)
- # clojure-art (3)
- # clojure-dev (79)
- # clojure-estonia (1)
- # clojure-europe (4)
- # clojure-finland (15)
- # clojure-indonesia (1)
- # clojure-italy (20)
- # clojure-nl (4)
- # clojure-spec (24)
- # clojure-sweden (2)
- # clojure-switzerland (1)
- # clojure-uk (99)
- # clojurescript (145)
- # cursive (8)
- # data-science (7)
- # datomic (26)
- # emacs (4)
- # figwheel-main (20)
- # fulcro (8)
- # graphql (3)
- # hoplon (2)
- # jobs (1)
- # kaocha (5)
- # leiningen (2)
- # liberator (19)
- # off-topic (16)
- # pathom (9)
- # perun (1)
- # portkey (2)
- # re-frame (17)
- # reitit (1)
- # shadow-cljs (26)
- # spacemacs (7)
- # vim (49)
Oh, sorry, I had a typo earlier I always ment to write :authorized?
(resource {:allowed-methods [:post :options]
:available-media-types ["application/edn" "application/json"]
:handle-options (fn [_]
(ring-response {}))
:handle-created (fn [{:keys [request] :as ctx}]
(let [{:keys [params]} request
{:keys [query]} params]
(ring-response
{:status 200
:body (when query (lacinia/execute foo/schema query nil nil))})))
:as-response (fn [d ctx]
(-> (as-response d ctx)
(assoc-in [:headers "Access-Control-Allow-Origin"] "*")
(assoc-in [:headers "Access-Control-Allow-Headers"] "Content-Type")))})
Is a way to not do :handle-options
which return nothing to add headers in :as-response
?Hmm according to https://github.com/clojure-liberator/liberator/blob/f6e3c7bce4d368e6b17e55076ff4f7a551190083/test/test_override_as_response.clj#L40-L45 it can be a bug.
@kwladyka I will look into that tomorrow
thank, at that moment I have this:
(resource {:allowed-methods [:post :options]
:new? false
:handle-options (constantly (ring-response {:status 401}))
:handle-no-content (fn [{:keys [request] :as ctx}]
(let [{:keys [params]} request
{:keys [email password]} params]
(if-let [uuid (auth/?login->uuid email password)]
(ring-response {:session {:uuid uuid}})
(ring-response {:status 401
:session nil}))))})
This is the best what I achieved so far(def handler-map
{:not-found (constantly (not-found "404 not found"))
;; authentication - only for web browser users from our domains
:authentication (resource {:allowed-methods [:post :options]
:new? false
:handle-options (constantly (ring-response {:status 204}))
:handle-no-content (fn [{:keys [request] :as ctx}]
(let [{:keys [params]} request
{:keys [email password]} params]
(if-let [uuid (auth/?login->uuid email password)]
(ring-response {:session {:uuid uuid}})
(ring-response {:status 401
:session nil}))))})
;; public API, authentication and authorization by token or session
:graphql (resource {:allowed-methods [:post :options]
:available-media-types ["application/edn" "application/json"]
:handle-options (constantly (ring-response {:status 204}))
:authorized? (fn [{:keys [request] :as ctx}]
(let [{:keys [session headers]} request
{:keys [uuid]} session
{:strs [authorization]} headers
token (some->> authorization
(re-matches #"(?i)Bearer\s([\d|a-f]{8}-(?:[\d|a-f]{4}-){3}[\d|a-f]{12})")
(second))]
(or (auth/?token->uuid token)
(auth/uuid-exist? uuid))))
:new? false
:respond-with-entity? true
:handle-ok (fn [{:keys [request] :as ctx}]
(let [{:keys [params]} request
{:keys [query]} params]
(ring-response
{:body (when query (lacinia/execute graphql/schema query nil nil))})))
:as-response (fn [d ctx]
(-> (as-response d ctx)
(assoc-in [:headers "Access-Control-Allow-Origin"] "*")
(assoc-in [:headers "Access-Control-Allow-Headers"] "Content-Type")))})})
I did progress