^ Thank you for that.
ok, so how can I help?
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}))}}}))
it should help to start
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 "<http://localhost:>" 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\":\"<mailto:foo@example.com|foo@example.com>\",\"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\":\"<mailto:foo@example.com|foo@example.com>\",\"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?
It is totally not up to date 🙂
The worst part about yada is documentation
If you want to figure out something read tests in git repository
Oohhh
That explains a couple of things
Thanks!
https://github.com/juxt/yada/search?q=defmethod+verify&unscoped_q=defmethod+verify how to write authentication code
you use it with :authentication-schemes
but I didn’t finish this yet
BTW :cookies
auth from doc is not up to date, it doesn’t work. There is even not code for that in yada repo.
@jaihindh.reddy the edge documentation is up to date, is that what you had issues with?
@dominicm It felt like that to me because Adapting Edge for new projects comes after Dev guide in the documentation. My bad. Too much coffee.
@jaihindh.reddy 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
Thanks, will try do this now
Actually, will have to wait. Making note now though.
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.
:yada.oauth2/secret
this is confuse too, because there is no such ns
oh the file was last modified in 2017
Should I consider using oauth2 from yada?
How do you use oauth2 in yada?