Skip to content Skip to sidebar Skip to footer

PassportJS Redirect Loop

Below is the code I have restify = require('restify') passport = require('passport') GoogleStrategy = require('passport-google').Strategy jsonContentType = (req, res, next) ->

Solution 1:

Your redirect loop is happening because passport can't parse the OpenId response which includes a number of query params. Restify has a bundled query parser you can use.

server.use restify.queryParser()

Although restify is similar to express, it does not have all of the APIs passport expects. A major one is res.redirect which is used for the failureRedirect and successRedirect options. You'll need to set the header and status manually like so:

server.get "/auth/google/return", passport.authenticate("google"),
    (req, res, next) ->
        res.header 'Location', '/'
        res.send 302 # redirect status

With those two additions, I was able to get it working locally (gist)


Post a Comment for "PassportJS Redirect Loop"