jaredhanson / passport-openidconnect

OpenID Connect authentication strategy for Passport and Node.js.
https://www.passportjs.org/packages/passport-openidconnect/?utm_source=github&utm_medium=referral&utm_campaign=passport-openidconnect&utm_content=about
MIT License
188 stars 173 forks source link

Sending specific state while calling passport.authenticate #77

Open kinjalkparmar opened 4 years ago

kinjalkparmar commented 4 years ago

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 commented 4 years ago

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 commented 2 years ago

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

revington commented 1 year ago

got same issue while trying to implement the solution provided in this comment https://github.com/jaredhanson/passport-oauth2/issues/96#issuecomment-403538004

navidkpr commented 1 year ago

Got the same issue trying to use custom state

sreelalkm commented 11 months ago

Any updates ?

Desocode commented 11 months ago

I have the same issue

mdelnegro-lennd commented 10 months ago

Same!

scarfunk commented 2 weeks ago

any update?