-
-
Notifications
You must be signed in to change notification settings - Fork 346
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
Is there a way to maintain query params from the initial request? #96
Comments
Here is my solution, achieved with subclassing class MyStrategy extends OauthStrategy {
authenticate(req: Request, options) {
// tslint:disable-next-line:no-string-literal
const callbackURL = options.callbackURL || this['_callbackURL']
options.callbackURL = addReturnTo(req, callbackURL)
return super.authenticate(req, options)
}
} |
To have a dynamic redirectUri via the options I had to change the following in strategy.js
to
and pass in the redirectUri with query parameters in the passport.authenticate() call, which I was doing anyways. If it's worth making a pr I'd be happy to |
I've been looking for a solution for this for a month. I was trying to use the |
@dgolant you can use state. here is how I do: app.get(`/auth`, (req, res, next) => {
const { returnTo } = req.query
const state = returnTo
? new Buffer(JSON.stringify({ returnTo })).toString('base64')
: undefined
const authenticator = passport.authenticate('google', { scope: [], state })
authenticator(req, res, next)
}) app.get(
`/auth/callback`,
passport.authenticate('google', { failureRedirect: '/-/login' }),
(req, res) => {
try {
const { state } = req.query
const { returnTo } = JSON.parse(new Buffer(state, 'base64').toString())
if (typeof returnTo === 'string' && returnTo.startsWith('/')) {
return res.redirect(returnTo)
}
} catch {
// just redirect normally below
}
res.redirect('/')
},
) |
@itajaja provided an awesome solution. i just wanted to mention that the |
@itajaja , Do I need to enable sessions (express-session) in your solution? Because every time i try to access state in the callback i get undefined. |
@albertonzn as far as I recall, you don't. there must be some other minor issue going on on your side |
@itajaja , thanks for you reply. It was a minor bug on my side. Everything is working now. |
Is there any update on this issue to keep query params from initial request? Cause so far all proposed solutions are work around. What is the reason to remove the query params from the request? |
I have this route:
When I visit
/auth?redirect_to=myInitialEncodedURL
, I get redirected to the oauth endpoint, without theredirect_to
parameter:But there's no
redirect_to
parameter. Is there any way this can be done?The text was updated successfully, but these errors were encountered: