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.
https://github.com/byrongibby/reitit/tree/master/examples/ring-swagger-buddy-auth
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 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 "<http://localhost:3000/upload>"
: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"} '<http://localhost:3000/upload>'
I think I got it:
(client/request
{:url "<http://localhost:3000/upload>"
:method :post
:multipart [{:name "file" :content (io/file "foo.json")}]})
I swear I tried that before.