jaredhanson/passport-twitter

Write Acess not working

Opened this issue · 2 comments

I am working on building an oauth flow with PassportJS for Twitter. I am looking to use the 'write' permissions to follow a user through the oauth'd Twitter account upon oauth authentication. Only issue is it's only giving me read permissions. I've setup the Read/Write permission settings in the Twitter app dashboard and modified the requestTokenURL in the strategy parameters yet the page that says what permissions the server is requesting isn't showing any write permissions just read.

const express = require('express');
const passport = require('passport');
const Strategy = require('passport-twitter').Strategy;

passport.use(new Strategy({
  consumerKey: 'XXX',
  consumerSecret: 'XXX',
  requestTokenURL: 'https://api.twitter.com/oauth/request_token?x_auth_access_type=write',
  callbackURL: 'XXX/oauth/callback'
}, (token, tokenSecret, profile, cb) => {
  console.log(profile, token, tokenSecret);
  return cb(null, profile);
}));

passport.serializeUser((user, cb) => {
  cb(null, user);
});

passport.deserializeUser((obj, cb) => {
  cb(null, obj);
});

let app = express();
app.use(require('express-session')({ secret: 'keyboard cat', resave: true, saveUninitialized: true }));
app.use(passport.initialize());
app.use(passport.session());

app.get('/', (req, res) => {
  res.send('<html><body><center><a href="/oauth/twitter">Login with Twitter</a></center></body></html>');
});

app.get('/oauth/twitter', passport.authenticate('twitter'));

app.get('/oauth/callback', passport.authenticate('twitter', { failureRedirect: '/' }), (req, res) => {
  res.send('<html><body><center><h3>You are now following the account and have notifications on!</h3></center></body></html>');
});

app.listen(3000, '0.0.0.0', (err) => {
  if(err) throw err;
  console.log('Server is now running');
});

Any update?

you can use the token and tokenSecret inside the Strategy callback to access Twitter's write API