Login with Twitter. OAuth without the nonsense.
Features
This module is designed to be the lightest possible wrapper on Twitter OAuth.
All this in < 100 lines of code.
Install
npm install login-with-twitter
Usage
Set up two routes on your web sever. We'll call them /twitter
and
/twitter/callback
, but they can be named anything.
Initialization
Initialize this module with the consumer key and secret for your Twitter App you created with an Twitter Developer account.
const LoginWithTwitter = const tw = consumerKey: '<your consumer key>' consumerSecret: '<your consumer secret>' callbackUrl: 'https://example.com/twitter/callback'
Login
Call login
from your /twitter
route, saving the OAuth tokenSecret
to use later. In this example, we use the request session (using, for example, express-session).
app
Callback
Then, call callback
from your /twitter/callback
route. The request will include oauth_token
and oauth_verifier
in the URL, accessible with req.query
. Pass those into callback
, along with the OAuth tokenSecret
you saved in the login
callback above, and a callback that handles a user
object that this module will return.
app;
Logout
If you want to implement logout, simply delete the user
object stored in the session.
For more information, check out the implementation in index.js.
license
MIT. Copyright (c) Feross Aboukhadijeh.