Skip to content

syuilo/autwh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

autwh

A simple Twitter API authentication helper.

NPM

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}.`);
});

License

MIT

About

Simple Twitter OAuth module for Node.js

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages