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

Sending specific state while calling passport.authenticate #77

Open
kinjalkparmar opened this issue Apr 1, 2020 · 10 comments
Open

Sending specific state while calling passport.authenticate #77

kinjalkparmar opened this issue Apr 1, 2020 · 10 comments

Comments

@kinjalkparmar
Copy link

kinjalkparmar commented Apr 1, 2020

Hi All,

I am sending a particular state parameter with the authenticate call as below. But that state is changed to a random string. How do I send a specific state and retrieve it after the callback url is called. Basically what I want is, I have couple of parameters based on which I will redirect to different routes. those i am trying to pass as state parameters, but they are changed to some random string and they are lost. How do I retrieve them. Thanks.

passport.authenticate('oidc', { state: JSON.stringify({ tab: 'placement' }) })

const passport = require('passport');
const OidcStrategy = require('passport-openidconnect').Strategy;

app.use(
session({
secret: crypto.randomBytes(64).toString('hex').substring(0, 20),
resave: true,
saveUninitialized: true,
})
);
app.use(passport.initialize());
app.use(passport.session());
passport.use(
'oidc',
new OidcStrategy(
{
issuer: 'xxxx',
authorizationURL: 'xxxx',
tokenURL: 'xxxx',
userInfoURL: 'xxxx',
clientID: 'xxxx',
clientSecret: 'xxxxx',
callbackURL: 'xxxxx',
scope: 'profile groups',
nonce: crypto
.randomBytes(64)
.toString('hex')
.substring(0, 20),
},
(issuer, sub, profile, accessToken, refreshToken, params, done) => {

  return done(null, profile);
}

)
);
app.use('/login',passport.authenticate('oidc', { state: JSON.stringify({ tab: 'placement' }) }) )`

@josephmulholland
Copy link

I've got the exact same issue. It appears that regardless of what is passed through in the options parameter of the .authenticate() call, the state parameter is ignored and randomly generated by the library:

https://github.com/jaredhanson/passport-openidconnect/blob/master/lib/state/session.js#L42

@newmanw
Copy link

newmanw commented Mar 27, 2022

Same issue here. Is it possible to use the StateStore in conjunction w/ other state params that app might need to round trip?

@revington
Copy link

got same issue while trying to implement the solution provided in this comment jaredhanson/passport-oauth2#96 (comment)

@navidkpr
Copy link

Got the same issue trying to use custom state

@sreelalkm
Copy link

Any updates ?

@Desocode
Copy link

Desocode commented Aug 1, 2023

I have the same issue

@mdelnegro-lennd
Copy link

Same!

@scarfunk
Copy link

any update?

@mrclicky
Copy link

mrclicky commented Aug 19, 2024

got same issue while trying to implement the solution provided in this comment jaredhanson/passport-oauth2#96 (comment)

I just struggled with this and found that the data is actually passed back but is listed under the property authInfo.

So the given callback request post authentication middleware looks like this:

try {
  const { state } = req.authInfo;   // <----------- THIS PROPERTY IS NOT 'query' but 'authInfo'
  const { returnTo } = JSON.parse(Buffer.from(state, 'base64').toString());
  if (typeof returnTo === 'string' && returnTo.startsWith('/')) {
	return res.redirect(returnTo)
  }
} catch {
  // just redirect normally below
}

@kumarchandresh
Copy link

I was also lost in finding the state query param.

Going to leave this article written by @jaredhanson as a reference:
https://medium.com/passportjs/application-state-in-oauth-2-0-1d94379164e

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