ring-oauth2
ring-oauth2 copied to clipboard
Help getting started with ring-oauth2 and Luminus
I'm trying to create a web server backed by github authentication using ring-oauth2
and Luminus. Here's what I've tried:
Added middleware to wrap the wrap-oauth2
function
;; src/clj/project/middleware.clj
;; :require [ring.middleware.oauth2 :refer [wrap-oauth2]]
(defn wrap-github-oauth2 [handler]
(wrap-oauth2
handler
{:github
{:authorize-uri "https://github.com/login/oauth/authorize"
:access-token-uri "https://github.com/login/oauth/access_token"
:client-id "abc"
:client-secret "123"
:scopes ["user:email"]
:launch-uri "/oauth2/github"
:redirect-uri "/oauth2/github/callback"
:landing-uri "/"}}))
then apply the middleware to my routes using the wrap-routes
function
;; src/clj/project/handlers.clj
(mount/defstate app
:start
(middleware/wrap-base
(routes
(-> #'home-routes
(wrap-routes middleware/wrap-csrf)
(wrap-routes middleware/wrap-formats)
(wrap-routes middleware/wrap-github-oauth2))
(route/not-found
(:body
(error-page {:status 404
:title "page not found"}))))))
When I access any of the URLs for home-routes
, I don't see any evidence that the middleware has been applied - no oauth2 redirects, no logs. I have no idea how to proceed debugging this - any advice?
I've extended the README with more information on how to get the middleware working. Let me know if that answers your question.
Don't know exactly what went wrong, but by looking at your code I think you miss some additional necessary wraps to the handlers according to the readme file. Secondly, I think you should wrap your wrap-github-oauth2 before you wrap all the necessary stuff because it seems the request is handled backwards.
PS: In terms of debugging, I think you can basically copy everything inside wrap-oauth2 and past into a new file so that you can debug yourself.