1.0.2 • Published 8 years ago

twitter-oauth-agent v1.0.2

Weekly downloads
21
License
-
Repository
github
Last release
8 years ago

twitter-oauth-agent

Bare bones, low-level agent for authenticating with Twitter's oAuth.

Uses both a client-side and server-side library to make the oAuth handshake more understandable.

This library does not make any assumptions about your server-side architecture, allowing it to easily adapt to any setup.

Example

Part 1: server.js

var Twitter = require('twitter-oauth-agent');

// Get the token and send to the client
Twitter({
  consumer_key: options.consumer_key,
  consumer_secret: options.consumer_secret,
  callback: query.callback || options.callback
}, function(err, token) {
  if (err) return res.status(500).send({ error: err.message });
  res.send(token);
})

Part 2: client.js

var Twitter = require('twitter-oauth-agent');

// Open popup with the token object sent from the server
Twitter(token, function(err, code) {
  // send "code" to server.js
})

Part 3: server.js

var Twitter = require('twitter-oauth-agent');

// received "code" from client, use it to
// fetch the full profile.
Twitter({
  consumer_secret: options.consumer_secret,
  oauth_verifier: body.oauth_verifier,
  consumer_key: options.consumer_key,
  oauth_token: body.oauth_token
}, function(err, profile) {
  // "profile" will contain your twitter information
});

Installation

npm install twitter-oauth-agent

Getting the keys

See also:

Credits

Most of this code is distilled from the satellizer project.

License

(The MIT License)

Copyright (c) 2015 Matthew Mueller <matt@lapwinglabs.com>