reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
WonderLastking 2021-04-14T16:03:10.091Z

Hello! I'm trying to use oauth2 lib https://github.com/weavejester/ring-oauth2 with reitit. But for some reason the uri-redirection (from oauth2) doesn't work. There is the following note in the lib: Please note, you should enable cookies to be sent with cross-site requests, in order to make the callback request handling work correctly, eg:

(wrap-defaults handler (-> site-defaults (assoc-in [:session :cookie-attrs :same-site] :lax)))
which I thought it was the main suspect. After a long debug session I figured out that indeed, something went wrong with the session. Did some search in google and found this https://github.com/metosin/reitit/issues/205 So, it seems that this is a reitit problem? I tried to apply any of the mentioned fixes but nothing worked. I use a default middleware this way (from here https://github.com/ring-clojure/ring-defaults) :
(defn site-defaults-middlewares
  [handler]
  (ring-mid-def/wrap-defaults handler (-> ring-mid-def/site-defaults
                                          (assoc-in [:security :anti-forgery] false)
                                          (assoc-in [:session :cookie-attrs :same-site] :lax))))
and I just have a github oauth2 middleware:
(defn github-oauth2-middleware
  [handler]
  (oauth2/wrap-oauth2
    handler
    {:github
     {:authorize-uri    "<https://github.com/login/oauth/authorize>"
      :access-token-uri "<https://github.com/login/oauth/access_token>"
      :client-id        "client-id"
      :client-secret    "secret"
      :scopes            ["user:email"]
      :launch-uri       "/oauth2/github"
      :redirect-uri     "/oauth2/github/callback"
      :landing-uri      "/welcome"}}))
finally my routers are define this way (ring/ring-handler (ring/router [["/routes"..{:handler ...}......]] {:data {:middleware [midlewares here....]})))

WonderLastking 2021-04-14T16:03:24.091300Z

Sorry for the long post, thanks in advance

WonderLastking 2021-04-14T16:03:26.091500Z

🙂