autwh
v0.1.0
Published
Twitter oAuth Helper
Downloads
1,442
Readme
autwh
A simple Twitter API authentication helper.
Install
$ npm install autwh
Usage
With Express
In this example, express-session is used, but other methods are also possible.
import autwh from 'autwh';
import * as express from 'express';
import * as session from 'express-session';
const twAuth = autwh({
consumerKey: 'kyoppie',
consumerSecret: 'yuppie',
callbackUrl: 'https://my.app.example.com/twitter/callback'
});
const app = express();
app.use(session());
app.get('/twitter/connect', async (req, res) => {
const ctx = await twAuth.begin();
req.session.ctx = ctx;
res.redirect(ctx.url);
});
// URL used in 'callbackUrl' above
app.get('/twitter/callback', async (req, res) => {
const ctx = await twAuth.done(req.session.ctx, req.query.oauth_verifier);
res.send(`Authorized! Hello ${ctx.screenName}.`);
});