Comments (4)
Do you have wrap-params
in your middleware? As the README says:
you must make sure that
ring.middleware.params/wrap-params
is enabled and runs before this middleware, as this library depends on the:query-params key
to be present in the request.
from ring-oauth2.
Hi, I am playing ring-oauth2 with compojure, all works well except the last step resulting in "No authorization code".
Here is handler.clj
:
(ns hello-compojure.handler
(:require [compojure.core :refer :all]
[compojure.route :as route]
[ring.middleware.defaults :refer [wrap-defaults site-defaults]]
[ring.middleware.params :refer [wrap-params]]
[ring.middleware.oauth2 :refer [wrap-oauth2]]
[selmer.parser :refer [render render-file]]
[selmer.util :refer [resource-path]]))
(defroutes app-routes
(GET "/login/" [] "<a href=\"/login/github\">github</a>")
(GET "/user/profile" request (str "whole request map:" request))
(route/not-found "Not Found"))
;; print the request
(defn- wrap-print-request [handler]
(fn
([request]
(println "print request sync:" (:uri request) (str request))
(handler request))
([request respond raise]
(println "print request async:" (:uri request) (str request))
(handler request respond raise))))
(def app
(let [profiles {:github
{:authorize-uri "https://github.com/login/oauth/authorize"
:access-token-uri "https://github.com/login/oauth/access_token"
:client-id conf-client-id
:client-secret conf-client-secret
:scopes ["user:email"]
:launch-uri "/login/github"
:redirect-uri "/login/github-callback"
:no-auth-code-handler (fn [request] {:status 401, :headers {}, :body (str "debug no code request:" request)})
:landing-uri "/user/profile"}}]
(-> app-routes
(wrap-defaults (assoc-in site-defaults [:session :cookie-attrs :same-site] :lax))
wrap-params
wrap-print-request
(wrap-oauth2 profiles)
)))
I have two questions:
- What's wrong with the above
wrap-params
? I can confirm with a debugging:no-auth-code-handler
that the request doesn't have:query-params
. - The debugging-purpose
wrap-print-request
doesn't work with URIs/login/github
and/login/github-callback
, but it works with "normal" URIs like "/user/profile", why is that?
Thanks.
from ring-oauth2.
Oops, it turns out that I place the middle-wares in wrong order, adjusting it to the below order fixes it:
(-> app-routes
wrap-print-request
(wrap-oauth2 profiles)
(wrap-defaults (assoc-in site-defaults [:session :cookie-attrs :same-site] :lax))
wrap-params)
P.S. @njerig did it due to the exact problem for you?
from ring-oauth2.
@whatacold Thank you, I have been struggling with this for an hours!
from ring-oauth2.
Related Issues (20)
- X-Forwarded-* headers are not used for resolving the URI HOT 1
- Help getting started with ring-oauth2 and Luminus HOT 2
- redirect-uri and provider differences HOT 4
- Scary error when forgetting `client_id` or `client_secret` HOT 1
- Internal Server Error/404 on callback from Youtube API HOT 1
- Enhancement: configure middleware for the internal POST calls HOT 2
- No reader function for tag object when using cookie store HOT 10
- cannot get the token HOT 4
- Is the example `ring-defaults` missing the actual handler in README.md? HOT 1
- Help: how to allow a local administrator to bypass? HOT 2
- Works when deployed to "/" but 404s when run with a context path HOT 2
- Logout Flow HOT 2
- refresh token functionality HOT 1
- Support for dynamic authorization URL params HOT 7
- Requesting a new release with redirect handler support HOT 1
- clj-http now requires cheshire 5.9.0 HOT 1
- Middelware does not work with Facebook? HOT 1
- Supporting multiple profiles for the same provider? HOT 5
- Unclear error messages HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ring-oauth2.