This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-25
Channels
- # aleph (12)
- # announcements (2)
- # beginners (40)
- # calva (8)
- # cider (26)
- # cljs-dev (71)
- # cljsrn (2)
- # clojure (122)
- # clojure-dev (9)
- # clojure-europe (2)
- # clojure-nl (2)
- # clojure-spec (42)
- # clojure-uk (20)
- # clojurescript (86)
- # cursive (15)
- # data-science (1)
- # datomic (42)
- # duct (4)
- # emacs (33)
- # events (1)
- # figwheel-main (2)
- # fulcro (33)
- # jobs (2)
- # jobs-discuss (46)
- # kaocha (13)
- # leiningen (9)
- # off-topic (62)
- # pathom (75)
- # quil (2)
- # re-frame (6)
- # reagent (13)
- # reitit (3)
- # shadow-cljs (52)
- # spacemacs (3)
- # specter (17)
- # sql (6)
- # tools-deps (2)
- # vim (3)
- # yada (28)
^ Thank you for that.
this is my research code:
(defn build-resource [model]
(-> (merge {} #_{:show-stack-traces? false} model)
(yada/resource)))
(def not-found
(-> (yada/as-resource nil)
(build-resource)))
(def authentication
(build-resource
{:id :authentication
:consumes #{"application/x-www-form-urlencoded" "application/edn" "application/json"}
; :access-control
:methods {:post {:produces "application/json"
:parameters {:form {:email String
:password String}}
:response (fn [{:keys [parameters] :as ctx}]
(get-in parameters [:parameters :form :query])
(println "ctx" (pr-str ctx))
;(println (pr-str body))
(println "parameters" (pr-str parameters))
;(println (pr-str form))
(let [{:keys [email password]} (:body parameters)]
{:token "foo"
:email email
:password password}))}}}))
(def graphql
(build-resource
{:id :graphql
:access-control {:realms {"session" {:authentication-schemes [{:scheme :cookie
:verify (fn [cookie]
(println "auth cookie" cookie)
{:a 1})}]
:authorization {:validate (fn [ctx creds]
(println "creds" creds)
ctx)}}}}
:produces #{"application/json" "application/edn"}
:methods {:post {:consumes #{"application/json" "application/graphql"}
:parameters {:body s/Any}
:response (fn [{:keys [authentication authorization body cookies] :as ctx}]
(println "ctx" ctx)
(println "cookies" cookies)
(println "authentication" authentication)
(println "authorization" authorization)
;(println "body" body)
;(println "request" (:request ctx))
(let [query (get-in ctx [:parameters :form :query])]
{:token "foo"
:query query}))}}}))
this is how I test:
(defmacro with-server [handler build-url & body]
`(let [listener# (yada/listener ~handler)
close# (:close listener#)
port# (:port listener#)
~build-url (fn [path#]
(str "" port# path#))]
(try
~@body
(finally
(close#)))))
(deftest graphql-test
(with-server core/handler build-url
(testing "Graphql"
(is (= 405 (-> @(http/request
{:url (build-url "/graphql")
:method :get})
:status))
"GET is not allowed.")
(is (= 401 (-> @(http/request
{:url (build-url "/graphql")
:headers {"Content-Type" "application/json"}
:method :post
:body "{\"email\":\"\",\"password\":\"qwaszx\"}"})
:status))
"Not authorized")
#_(is (= 200 (-> @(http/request
{:url (build-url "/graphql")
:headers {"Content-Type" "application/json"}
:method :post
:params {:query "{ game_by_id(id: \"1237\") { name designers { name }}}"}})
:status))
"Authentication by session")
(is (= 200 (-> @(http/request
{:url (build-url "/graphql")
:headers {"Content-Type" "application/json"
"Authorization" "bearer 89abddfb-2cff-4fda-83e6-13221f0c3d4f"}
:method :post
:body "{\"email\":\"\",\"password\":\"qwaszx\"}"})
:status))
"Authentication by token"))))
I converged to something very similar yesterday. No graphql though.
Also, I tried to get juxt/edge working but couldn't
Is the documentation up to date?
@UBU6QCSJH the edge documentation is up to date, is that what you had issues with?
@U09LZR36F It felt like that to me because Adapting Edge for new projects comes after Dev guide in the documentation. My bad. Too much coffee.
@UBU6QCSJH I'll take that feedback on! It's quite difficult to figure out the structuring for this stuff. Thank you!
Also, s/discreet/discrete/g
on https://juxt.pro/edge/docs/why-edge.html
That explains a couple of things
https://github.com/juxt/yada/search?q=defmethod+verify&unscoped_q=defmethod+verify how to write authentication code
BTW :cookies
auth from doc is not up to date, it doesn’t work. There is even not code for that in yada repo.
https://github.com/juxt/yada/blob/master/ext/oauth2/src/yada/oauth.clj - I think this code is not up to date, especially {cookie "session"}
. There is no way to set different cookie name. Probably doesn’t matter but can be confused.