This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-07-08
Channels
- # announcements (5)
- # aws (15)
- # babashka (7)
- # beginners (138)
- # bristol-clojurians (2)
- # chlorine-clover (11)
- # cider (9)
- # clara (4)
- # clj-kondo (17)
- # cljsrn (20)
- # clojars (1)
- # clojure (73)
- # clojure-europe (17)
- # clojure-italy (1)
- # clojure-nl (9)
- # clojure-spec (4)
- # clojure-uk (9)
- # clojurescript (43)
- # data-science (1)
- # datomic (87)
- # emacs (2)
- # figwheel-main (30)
- # fulcro (71)
- # helix (2)
- # hugsql (4)
- # jackdaw (5)
- # jobs (3)
- # jobs-discuss (31)
- # juxt (5)
- # kaocha (6)
- # lein-figwheel (16)
- # leiningen (1)
- # luminus (4)
- # malli (2)
- # meander (54)
- # music (8)
- # nrepl (12)
- # observability (28)
- # off-topic (85)
- # pathom (11)
- # re-frame (99)
- # reitit (9)
- # ring (1)
- # rum (6)
- # sci (11)
- # shadow-cljs (102)
- # sql (22)
- # tools-deps (10)
- # vim (65)
- # xtdb (14)
Does anyone know an example that shows how authentication & authorization is done with reitit?
Hey. I am busy figuring this out myself at the moment. I decided to go with https://github.com/funcool/buddy-auth. Let me know if you have any questions I can help you answer.
I created an example building on a previous one. Not sure if this is the recommended way of doing things, but it works for me. Let me know if it is useful.
I used a combination of this https://luminusweb.com/docs/routes.html. https://adambard.com/blog/clojure-auth-with-buddy/ by Adam Bard and this https://www.reddit.com/r/Clojure/comments/2mjfh6/reagent_web_app_authentication/post.
Iām a bit late for the party but I have an open-source example of Buddy & Reitit using old-school middleware. The solution combines http-basic auth and JWT-tokens. Route with http-basic-auth middleware https://github.com/lipas-liikuntapaikat/lipas/blob/master/webapp/src/clj/lipas/backend/handler.clj#L177 Route with token-auth middleware https://github.com/lipas-liikuntapaikat/lipas/blob/master/webapp/src/clj/lipas/backend/handler.clj#L151 Middleware definitions https://github.com/lipas-liikuntapaikat/lipas/blob/master/webapp/src/clj/lipas/backend/middleware.clj Authentication backend definitions https://github.com/lipas-liikuntapaikat/lipas/blob/master/webapp/src/clj/lipas/backend/auth.clj Hope this helps somebody!
I whipped up a PR with annotated example how to use Buddy to implement simple authentication and authorization with reitit. https://github.com/metosin/reitit/pull/419 Feedback is very welcome. š
I have this route running on localhost and am trying to post a file to it using clj-http.
["/upload" {:post {:summary "upload an artifact"
:parameters {:multipart {:file multipart/temp-file-part}}
:handler (fn [request]
(ok (select-keys
request
[:form-params
:query-params
:path-params
:parameters])))}}]
I've tried a wide variety of permutations of the client invocation. For example, this contains some of the variants:
(let [mp {:name "foo.json" :content (io/file "foo.json")}]
(->> {:method :post
:throw-exceptions false
:url ""
:params {:file mp}
:form-params {:file mp}
:multipart-params {:file mp}
:multipart [mp]
}
client/request
:body
ch/parse-string))
I keep getting this spec error:
{"spec" "(spec-tools.core/spec {:spec (clojure.spec.alpha/keys :req-un [:spec$47151/file]), :type :map, :leaf? false})",
"problems" [{"path" [],
"pred" "(clojure.core/fn [%] (clojure.core/contains? % :file))",
"val" {},
"via" [],
"in" []}],
"type" "reitit.coercion/request-coercion",
"coercion" "spec",
"value" {},
"in" ["request" "multipart-params"]}
Somehow I need to modify my client request to make the service happy. Any ideas as to what the right client request is?
Here is working curl version:
curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' {"type":"formData"} ''
I think I got it:
(client/request
{:url ""
:method :post
:multipart [{:name "file" :content (io/file "foo.json")}]})
I swear I tried that before.Iām a bit late for the party but I have an open-source example of Buddy & Reitit using old-school middleware. The solution combines http-basic auth and JWT-tokens. Route with http-basic-auth middleware https://github.com/lipas-liikuntapaikat/lipas/blob/master/webapp/src/clj/lipas/backend/handler.clj#L177 Route with token-auth middleware https://github.com/lipas-liikuntapaikat/lipas/blob/master/webapp/src/clj/lipas/backend/handler.clj#L151 Middleware definitions https://github.com/lipas-liikuntapaikat/lipas/blob/master/webapp/src/clj/lipas/backend/middleware.clj Authentication backend definitions https://github.com/lipas-liikuntapaikat/lipas/blob/master/webapp/src/clj/lipas/backend/auth.clj Hope this helps somebody!