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

error with absence of oauth:twitter key #36

Open
vetsinen-onlyfans opened this issue Jan 11, 2023 · 7 comments
Open

error with absence of oauth:twitter key #36

vetsinen-onlyfans opened this issue Jan 11, 2023 · 7 comments

Comments

@vetsinen-onlyfans
Copy link

can you say what is a reason for error with absent key oauth:twitter on callback?
debug shows error in if
node_modules/passport-oauth2/lib/state/pkcesession.js
line 67
var key = this._key;
if (!req.session[key]) {
return callback(null, false, { message: 'Unable to verify authorization request state.' });
}

@jnv
Copy link
Collaborator

jnv commented Jan 11, 2023

Hello, I'm not sure I can help you without seeing how you setup the strategy and Express. Do you have express-session set up correctly?

@vetsinen-onlyfans
Copy link
Author

vetsinen-onlyfans commented Jan 11, 2023

Hello, I'm not sure I can help you without seeing how you setup the strategy and Express. Do you have express-session set up correctly?

`
module.exports = new TwitterStrategy({
passReqToCallback: true,
callbackURL: config.twitter.login.callbackURL,

clientID: config.twitter.login.clientID,
clientSecret: config.twitter.login.clientSecret,
clientType: 'public',

}, (req, accessToken, refreshToken, params, done) => {
console.log('twitter ', params)
return social_auth(req, params, done, 'twitter');
})
`

@jnv
Copy link
Collaborator

jnv commented Jan 11, 2023

I don't think it makes sense to combine the public client with client secret, but to be honest I never tried to implement the public client. Did you, @janhalama?

@janhalama
Copy link
Collaborator

I tried the public client. You do not need to provide client secret.

This is the Strategy setup:

new TwitterStrategy(
    {
      clientID: process.env.TWITTER_CLIENT_ID,
      callbackURL: `${process.env.BASE_URL}/auth/twitter/callback`,
      clientType: 'public',
    },
    (accessToken, refreshToken, profile, done) => {
      onAuthSuccess({ accessToken, refreshToken });
      return done(null, {
        displayName: profile.displayName,
      });
    }
  )

What is breaking the authentication is the passReqToCallback option enabled. I will look into int tomorrow.

@janhalama
Copy link
Collaborator

I checked it once again and the problem was in verification callback implementation. The strategy works just fine with the option passReqToCallback enabled.

Here is the Strategy setup:

new TwitterStrategy(
    {
      passReqToCallback: true,
      clientID: process.env.TWITTER_CLIENT_ID,
      callbackURL: `${process.env.BASE_URL}/auth/twitter/callback`,
      clientType: 'public',
    },
    (_req, accessToken, refreshToken, profile, done) => {
      onAuthSuccess({ accessToken, refreshToken });
      return done(null, {
        displayName: profile.displayName,
      });
    }
  )

I tested it with the twitter-demo example. The only change to the project is the code above.

@janhalama
Copy link
Collaborator

From the error you provided it looks like some problem with express-session set up. @jnv already pointed it out.

@jnv
Copy link
Collaborator

jnv commented Jan 13, 2023

I think I should mention session requirement + possible way how to work around it in the readme, see also #23. Probably add FAQ question to collect these.

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

3 participants