Ad

How To Get "Sign In With Twitter" Working With NodeJS

- 1 answer

Im trying to implement Sing In with Twitter working, however i keep getting the following error

Whoa there! The request token for this page is invalid. It may have already been used, or expired because it is too old. Please go back to the site or application that sent you here and try again; it was probably just a mistake.

Here's my code, the what am I doing wrong?

// Server
var OAuth = require('oauth').OAuth;
var callbackUrl = null;
var oa = new OAuth(
    'https://api.twitter.com/oauth/request_token',
    'https://api.twitter.com/oauth/access_token',
    CONSUMER_KEY,
    CONSUMER_SECRET,
    '1.0',
    callbackUrl,
    'HMAC-SHA1'
);

const promise = new Promise((resolve, reject) => {
    oa.getOAuthRequestToken(function(error, token, secret, results) {
        resolve({
            token,
            secret,
        });
    });
});

var oauth = await promise;
return { oauth };

// Client
window.open(`https://api.twitter.com/oauth/authenticate?oauth_token=${twitter.oauth.token})`);

I've also set the callback url to the same as what I have in the app details page, but no dice!

var callbackUrl = 'http://0.0.0.0:3001/settings/social/twitter/oauth';

Small note, not sure if it helps, but I've noticed the returned tokens are shorter than the examples I've seen online. Example:

Mine: EBhy3AAAAAAA94TPAAABajDwCww%
Twitter Site: NPcudxy0yU5T3tBzho7iCotZ3cnetKwcTIRlX0iwRl0&
Ad

Answer

My client code had an extra ")"

window.open(`https://api.twitter.com/oauth/authenticate?oauth_token=${twitter.oauth.token})`);

should read

window.open(`https://api.twitter.com/oauth/authenticate?oauth_token=${twitter.oauth.token}`);
Ad
source: stackoverflow.com
Ad