question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:10
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
PhilippSpocommented, May 12, 2017

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

const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));
6reactions
mrchiefcommented, 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. 😞

Read more comments on GitHub >

github_iconTop Results From Across the Web

Express Authentication Redirects Leading to Infinite Loop
The ensureAutheticated will check whether your code is authenticated or not.Not need to redirect it every time through the login route.
Read more >
URL Rewriting Middleware in ASP.NET Core - Microsoft Learn
It's easy to accidentally create a loop of infinite redirects. The part of the expression contained within parentheses is called a capture ...
Read more >
Node.js best practices list (July 2021) - DEV Community ‍ ‍
1. Project Structure Practices · 1.1 Structure your solution by components · 1.2 Layer your components, keep the web layer within its boundaries....
Read more >
Creating a Basic To-Do App with Node.js
The event loop is an infinite loop and is the only thread available. The event mechanism helps the server to respond in a...
Read more >
18.4.2 API Reference - hapi.dev
If not configured, defaults to host if present, otherwise to all available ... listed returned a non-error response (e.g. a redirect to a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found