I'm trying to implement a REST API using Kit. My routes are defined as follows:
(defn api-routes [_opts]
["/auth/login" {:post auth/login}]
["/auth/checked" {:get (wrap-auth auth/checked)}]
["/auth/open" {:get auth/open}]])
The /auth/login endpoint returns a signed JWT, which works fine. Now I'd like the endpoint /auth/checked to run through authenticaton, while /auth/open remains open. The endpoints don't do anything meaningful:
(defn checked [_req] {:status 200 :body "require auth"})
(defn open [_req] {:status 200 :body "without auth"})
More important is the wrap-auth function, defined as follows:
(defn wrap-auth [handler]
(let [backend (backends/jws {:secret "topsecret"})]
(-> handler
(auth-middleware/wrap-authentication backend)
(auth-middleware/wrap-authorization backend))))
With backend coming from buddy.auth.backends.
However, both endpoints work without any Authorization header.
I'm totally lost how middlewares are supposed to be applied to some routes but not to others. Any ideas how to do this?
Is there any Kit demo application that makes use of JWT bearer authentication?
I'm looking at the Kit documentation on how to restrict access but don't understand anything.