Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirects in infinite loop if a body parser is not set up for express #128

Closed
jrop opened this issue Nov 24, 2015 · 11 comments
Closed

Redirects in infinite loop if a body parser is not set up for express #128

jrop opened this issue Nov 24, 2015 · 11 comments

Comments

@jrop
Copy link

jrop commented Nov 24, 2015

Minor, but should be documented: when defining the callback route:

let app = express()
app.get('/login', passport.authenticate('saml', { failureRedirect: '/' }), (req, res) => res.redirect('/'))
app.post('/callback', passport.authenticate('saml', { failureRedirect: '/' }), (req, res) => res.redirect('/'))

There needs to be middleware that supports body parsing, otherwise (in my case) it starts redirecting between my IdP and my app indefinitely.

@ploer
Copy link
Contributor

ploer commented Dec 30, 2015

Can you submit a PR with the proposed documentation change? Thanks!

@joelwass
Copy link

I seem to be having this issue, but i'm using the node package body-parser, what body parser did you end up using to resolve this issue?

@ghost
Copy link

ghost commented Feb 16, 2017

I feel like adding the body-parser middleware has caused functionality in Rocky to break. When trying to reverse-proxy connections after ensuring authentication, the middleware fails with:

TypeError: Invalid non-string/buffer chunk
at chunkInvalid (_stream_readable.js:380:10)
at readableAddChunk (_stream_readable.js:125:12)
at Readable.push (_stream_readable.js:111:10)
at createBodyStream (/usr/src/app/node_modules/rocky/lib/protocols/http/passes/forward.js:165:10)
at useRequestBody (/usr/src/app/node_modules/rocky/lib/protocols/http/passes/forward.js:143:19)
at forwardRequest (/usr/src/app/node_modules/rocky/lib/protocols/http/passes/forward.js:118:3)
at forwardStrategy (/usr/src/app/node_modules/rocky/lib/protocols/http/passes/forward.js:58:5)
at forwarder (/usr/src/app/node_modules/rocky/lib/protocols/http/passes/forward.js:40:5)
at next (/usr/src/app/node_modules/midware/midware.js:53:26)
at run (/usr/src/app/node_modules/midware-pool/lib/pool.js:84:29)

The body seems to just have a "{}" in it, and it doesn't seem to know how to proxy the request.

@PhilippSpo
Copy link

I also had the same issue. Adding the bodyParser finally resolved it. 😅

const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));

@mrchief
Copy link

mrchief commented Jul 25, 2017

Wasted days chasing this infinite loop issue. Many thanks to OP for creating this issue. There is no mention of it in documentation. 😞

@jrop
Copy link
Author

jrop commented Jul 25, 2017

@mrchief I created a PR for this a long time ago, but it's had very little activity :( #151

@salazr
Copy link

salazr commented Aug 10, 2017

Spent a couple hours this morning setting this up on a new app, and encountered the same problem. It would be nice to have this in the documentation.

@MardariG
Copy link

MardariG commented Nov 2, 2018

This is closed, but I have spend too much time to find out the problem is in body-parser.
This should be as mandatory requirement on the mine README in bold. I don't get it why is so hard to mention this. Thanks for awesome library anyway.

kashiif pushed a commit to kashiif/passport-saml that referenced this issue Dec 12, 2018
@Lrigh1
Copy link

Lrigh1 commented Feb 13, 2020

Hello! If anyone is using express 5, since body parser isn't needed, simply make sure the app.use(express.urlencoded({ extended: false })); is before the route calls.

Many thanks to @kashiif and @markstos above for leading me down that path. Immense Thanks!

@markstos
Copy link
Contributor

@DORRITO Please submit a doc-patch for the Express 5 example syntax.

@duxing
Copy link

duxing commented May 16, 2020

another victim who wastes days here. Thanks for sharing this and saving my life @jrop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants